问题描述
您好,我有一个有关消息窗口的问题.我有一个类(基于CWnd),在其中创建了仅消息窗口.然后我添加
Hi I have a question regarding message windows. I have a class (CWnd based), in which I create a message only window. Then I add the
BEGIN_MESSAGE_MAP(MyClass, CWnd)
//{{AFX_MSG_MAP(MyClass)
ON_REGISTERED_MESSAGE(WM_MyClass_MSG_TO_THREAD,OnMyClassMsg2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
然后在一个工作线程中创建一个该类
MyClass * class =新的MyClass;
现在在UI线程中找到窗口
:: FindWindow(...);
然后向其发布消息
:: PostMessage(...);
我使用用户注册的消息,但确实找到了该窗口,但是该消息从未被该窗口捕获,因此OnMyClassMsg2函数中没有任何内容.
then in a working thread I create a that class
MyClass *class = new MyClass;
Now in the UI thread I find the window
::FindWindow(...);
and then post a message to it
::PostMessage(...);
I use user registered messages, I do find the window, but the message is never captured by the window, so I don''t get anything in the OnMyClassMsg2 function.
Is there anything wrong I''m doing?
推荐答案
while ( im_not_doing_anything_else )
{
MSG m;
GetMessage(&m,0,0,0);
TranslateMessage(&m);
DispatchMessage(&m);
}
MyClass *class = new MyClass;
MyClass->create();
请参阅: http://msdn.microsoft.com/en-us/library /0yhc9kx4(v=VS.90).aspx [ ^ ]
See: http://msdn.microsoft.com/en-us/library/0yhc9kx4(v=VS.90).aspx[^]
void MyClass::MyClass(void){
CString wnd_class_name = ::AfxRegisterWndClass(NULL);
this->CreateEx(0,wnd_class_name, "TEST_THREAD_WINDOW",0 ,0 ,0 ,0 ,0 ,HWND_MESSAGE,0);
TRACE("WINDOW READY\n");
}
我按照您的建议进行了操作,结果是一样的,正如我所说,我可以找到该窗口,FindWindowEx(..)返回HWND,因此该窗口在那里,但是消息根本没有被它捕获.我已经仔细检查了registers消息,依此类推,一切正常,但是接收消息的功能没有结果.
我的意思是FindWindowEx,当然不是FindWindow.
I did what you suggested and the result was the same, as I said, I can find the window, the FindWindowEx(..) returns HWND, so the window is there, but the message is simply not captured by it. I have double checked the registers message and so on and everything is ok, but no result in the function for the received message.
I mean FindWindowEx, not FindWindow of course.
这篇关于消息窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!