Detecting whether a modal dialog has displayed
-
Inside a message handler for
WM_LBUTTONDOWN
, several functions are being called, one of which is known to display a dialog box under certain circumstances. Prior to this function being called, the mouse is captured usingSetCapture()
. However when that dialog is shown, theWM_LBUTTONUP
appears to be getting swallowed by that dialog, and as such, to the underlying control that spawned the dialog, the mouse still appears to be down. In looking for a passive method of detecting whether the dialog has been displayed, the code will callGetCapture()
to retrieve the handle to the current window with the capture and check it against the handle to which the capture had been previously set. If the handles are different, it will post aWM_LBUTTONUP
message to the message queue to "complete the click". Sample code:::SetCapture(hWnd);
// ...several lines later
FunctionThatCouldDisplayADialog();
HWND hWndCapture = ::GetCapture();
if(hWnd != hWndCapture)
{
::PostMessage(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
}With some testing of various scenarios (with more to come), this appears to be a reliable method to determine if a dialog was displayed during the current line of execution. To quote the manager of my team, this wreaks of being a hack, and as such, we're still mildly skeptical on the reliability of this method. I'm looking for feedback on this and whether anyone can see any potential pitfalls, issues or concerns for which we should be accounting. Thanks.
-
Inside a message handler for
WM_LBUTTONDOWN
, several functions are being called, one of which is known to display a dialog box under certain circumstances. Prior to this function being called, the mouse is captured usingSetCapture()
. However when that dialog is shown, theWM_LBUTTONUP
appears to be getting swallowed by that dialog, and as such, to the underlying control that spawned the dialog, the mouse still appears to be down. In looking for a passive method of detecting whether the dialog has been displayed, the code will callGetCapture()
to retrieve the handle to the current window with the capture and check it against the handle to which the capture had been previously set. If the handles are different, it will post aWM_LBUTTONUP
message to the message queue to "complete the click". Sample code:::SetCapture(hWnd);
// ...several lines later
FunctionThatCouldDisplayADialog();
HWND hWndCapture = ::GetCapture();
if(hWnd != hWndCapture)
{
::PostMessage(hWnd, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
}With some testing of various scenarios (with more to come), this appears to be a reliable method to determine if a dialog was displayed during the current line of execution. To quote the manager of my team, this wreaks of being a hack, and as such, we're still mildly skeptical on the reliability of this method. I'm looking for feedback on this and whether anyone can see any potential pitfalls, issues or concerns for which we should be accounting. Thanks.
Can you check if you can use WM_ACTIVATE message on your main window?. The state is supposed to be WA_INACTIVE when the dialog box is displayed.
-
Can you check if you can use WM_ACTIVATE message on your main window?. The state is supposed to be WA_INACTIVE when the dialog box is displayed.
Unfortunately given the way the solution is overall designed, that is not possible.