开发者

Calling Win32 API SendMessage in C# richtextbox to copy selected text returns one character less

开发者 https://www.devze.com 2022-12-13 14:59 出处:网络
I am trying to copy the selected text in the active window using the win32 API SendMessage as following

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消