开发者

Program Freezes on MessageBox()

Here's the problem: The main GUI thread is performing a SendMessage to another GUI thread (yes, there are multiple GUI threads, and unfortunately this cannot change). When that second GUI thread receives the SendMessage, it may decide to display a message box. Some of the time, that MessageBox will 'freeze' the entire application.

More specifically, the message box shows up, but the entire GUI is hung (user input does not work anywhere).

I've verified with a debugger that the second GUI thread is spinning in the DialogBox2() function defined in user32.dll. I can see in the disassembly that a message pump is being executed (I see IsDialogMessage/TranslateMessage/DispatchMessage being called). Using spy++, I do not see any messages being processed for the message dialog box window. I do see messages getting processed on the main GUI window (such as WM_SETCURSOR, though I do not thin they are being processed as I believe SendMessage doesn't execute a message pump).

The second thread is executing code that is part of an MFC extension DLL, if that matters.

I've tried using AfxMessageBox() / CWnd::MessageBox / ::MessageBox(NULL parent window,...). All exh开发者_运维百科ibit the same problem.

Has anyone seen anything similar before?

Thanks, Andrew


It must be that blocking one of the GUI threads causes the problem.

Try this:

Replace the ::SendMesage with ::PostMessage followed by a ::MsgWaitForMultipleObjects loop. You will need to pass an event handle that signals when the message box is closed.

It will probably solve the problem.

Just be careful which messages you dispatch in you ::MsgWaitForMultipleObjects loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜