当我尝试将文本粘贴到另一个程序的文本框中时,插入了文本,但程序无法识别它。
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const uint WM_SETTEXT = 0x000C;
IntPtr text = Marshal.StringToCoTaskMemUni("100");
IntPtr thisWindow = FindWindow(null, "AnotherWindow");
IntPtr handle = FindWindowEx(thisWindow, IntPtr.Zero, "AnotherTextBox", null);
SendMessage(handle, WM_SETTEXT, IntPtr.Zero, text);
Marshal.FreeCoTaskMem(text);
也许我应该向父母发送一条文本框已更新的消息?像这样:
//Wrong code, because I do not know how correctly send a message
SendMessage(handle, WM_COMMAND, EM_SETMODIFY, handle);