Date: | April 5, 2005 / year-entry #86 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20050405-46/?p=35973 |
Comments: | 3 |
Summary: | Last time, I left you with a homework exercise: Find the subtle bug in the interaction between EndManualModalDialog and the modal message loop. The subtlety is that EndManualModalDialog sets some flags but does nothing to force the message loop to notice that the flag was actually set. Recall that the GetMessage function does not return... |
Last time, I left you with a homework exercise:
Find the subtle bug in the interaction between
The subtlety is that
The bug, therefore, is that when you call
There are a few ways of fixing this problem. The quick solution is to post a meaningless message. void EndManualModalDialog(HWND hdlg, int iResult) { DIALOGSTATE *pds = reinterpret_cast<DIALOGSTATE*> (GetWindowLongPtr(hdlg, DWLP_USER)); if (pds) { pds->iResult = iResult; pds->fEnded = TRUE; PostMessage(hdlg, WM_NULL, 0, 0); } }
This will force the Next time, a different solution to the same problem. |
Comments (3)
Comments are closed. |
I wornder whether this is the reason, why using TrackPopupMenu() requires posting WM_NULL at the end
Fixing the EndManualModalDialog bug a different way.
Fixing the EndManualModalDialog bug a different way.