[英]Why can't I create a dialog in one thread and deal with its message in another thread?
I did something like this : 我做了这样的事情:
Thread 1 : 线程1:
pDlg = new CAxDialogImpl<A>();
// start thread2 here
Thread 2 : 线程2:
pDlg->Create();
while(GetMessage(&msg, 0, 0, 0) > 0)
{
...
}
Code like this leads to crash. 这样的代码会导致崩溃。 Is there anybody can explain why ?
有没有人能解释一下为什么?
It depends where the underlying window (HWND) is created. 这取决于基础窗口(HWND)的创建位置。 If the CAxDialogImpl constructor creates the window then it would live on thread 1 and messages for it could not be processed on thread 2. If the CAxDialogImpl::Create() method creates the HWND then it would live on thread 2 and messages could be happily processed there.
如果CAxDialogImpl构造函数创建窗口,则它将驻留在线程1上,并且无法在线程2上处理该消息。如果CAxDialogImpl :: Create()方法创建了HWND,则它将驻留在线程2上并且消息可能很愉快在那里处理。
Where does the actual crash occur? 实际的崩溃发生在哪里?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.