MessageBox does not appear when opening WM_CLOSE processing from the close taskbar thumbnail button

An attempt to set the “Do you want to save” dialog when trying to close the window using the close button in the thumbnail of the taskbar in Windows 7 (with the aero peek function active).

Using MessageBox () while processing WM_CLOSE does not work. MessageBox will not be displayed until you click on the thumbnail, so aero peek is disabled.

Many applications have this erroneous behavior, so this is probably a design flaw in Windows 7, but it works for some programs (Word, Notepad, Visual Studio, ...), so I wonder what trick they use (or what required to "exit" from aero peek-mode).

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

+3
source share
2 answers

I put together a small application to reproduce this problem. I was able to successfully open the message box by calling SetForegroundWindow before calling the 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;
+1
source

I would execute a handler for WM_SYSCOMMAND and run the behavior of the SC_CLOSE message defining the application that will display your user interface and post the WM_CLOSE message to the original window if the user wants to exit.

Notepad, , , . ?

0

Source: https://habr.com/ru/post/1747152/


All Articles