المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Detecting whether a modal dialog has displayed



C++ Programming
01-12-2010, 11:17 PM
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 using SetCapture(). However when that dialog is shown, the WM_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 call GetCapture() 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 a WM_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.