I am trying to copy the selected text in the active window using the win32 API SendMessage as following
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, out int wParam, out int lParam);
int start,next;
SendMessage(activeWindowHandle, 0xB0, out start, out next);
This returns the starting and ending character position of the selected text. This works开发者_运维知识库 fine in notepad or any System.Windows.Forms.TextBox. But calling this for a System.Windows.Forms.RichTextBox returns one character less. anyone know why?? and how to work around this.
SendMessage should actually be
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
wParam and lParam are in fact inputs, not outputs. Hence, you're sending garbage, and lucky to get something back.
精彩评论