【发布时间】:2011-10-24 22:17:55
【问题描述】:
我目前正在尝试通过 C# pinvoke 使用 SendMessage 从子窗口获取一些文本。但是,我之前对窗口句柄进行硬核的尝试失败了,因为值在应用程序启动时发生了变化。有没有办法可靠地获取这个子窗口的窗口句柄? Winspector spy 显示这个窗口的类名是 RichEdit20W。我目前的代码如下:
IntPtr hWnd= (IntPtr) 0xA0E88; // Hardcode window handle
int txtlen = SendMessage(hWnd, WM_GETTEXTLENGTH, 20, null);
StringBuilder text = new StringBuilder(txtlen);
int RetVal = SendMessage(hWnd, WM_GETTEXT, text.Capacity, text);
【问题讨论】: