开发者

MessageBox not shown when opened processing WM_CLOSE from taskbar thumbnail close button

Trying to put up a "Do you want to save"-dialog when trying to close window with close-button in taskbar thumbnail in windows 7(with aero peek active).

Using MessageBox() when processing WM_CLOSE does not work. MessageBox won't show until you move mouse cursor outside thumbnail so aero peek is disabled.

Lots of applications have this buggy behaviour so it's probably a design flaw in Windows 7, but for some programs it works (Word, Notepad, Visual Studio, ...), so I'm wondering w开发者_StackOverflowhat trick they are using(or what it takes to "exit" aero peek-mode programmatically).

The small "Sound Recorder" application that comes with Windows 7 has the same problem (if you have recorded something without saving and try to close it using thumbnail close-button)...


I put together a small app to reproduce this problem. I was able to successfully get the message box to appear by calling SetForegroundWindow before calling MessageBox.

case WM_SYSCOMMAND:
    if (wParam == SC_CLOSE)
    {
        SetForegroundWindow(hWnd);
        MessageBox(hWnd, L"Are you sure you want to exit", L"Close Window", MB_OK);
    }
    else
    {
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;


I would implement a handler for WM_SYSCOMMAND and have the SC_CLOSE behavior post a application-defined message, which would display your UI, and post a WM_CLOSE to the original window if the user wants to exit.

Alternatively, Notepad appears to be using a task dialog, rather than a message box. Have you tried that?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜