我试图将文本从另一个应用程序的编辑控件中设置为一个C++ MFC应用程序。
如果另一个应用程序是记事本,我的代码可以正常工作,但它不能在我需要它工作的应用程序上工作。当我无法让wm_settext工作时,我想也许应用程序正在将消息过滤到控件,并且由于键盘输入工作,我尝试发送键盘消息。这也不起作用。我通过在spy++中记录消息来验证窗口是否接收到键盘输入。我做错了什么或错过了什么?
if (g_IPAdressHwnd != 0) // g_IPAdressHwnd is the handle to the Edit control
{
CWnd *wnd = CWnd::FromHandle(g_IPAdressHwnd);
wchar_t buff[256];
wchar_t windowText[256];
wchar_t className[256];
BOOL b = IsWindowUnicode(wnd->GetSafeHwnd()); // returns true
GetClassName(wnd->GetSafeHwnd(), className, 200); // returns "WindowsForms10.EDIT.app.0.378734a"
wnd->GetWindowText(windowText, 256); // does not work
wnd->SendMessage(WM_GETTEXT, 256, (LPARAM)buff); // this works
wcscpy_s(buff, L"Foo!");
wnd->SendMessage(WM_SETTEXT, 256, (LPARAM)buff); // does not work
wnd->SendMessage(WM_CHAR, L'A', 0); // does not work
}