简体   繁体   中英

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 :

pDlg = new CAxDialogImpl<A>();
// start thread2 here

Thread 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. 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.

Where does the actual crash occur?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM