views:

90

answers:

1

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 what 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)...

A: 

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?

Eric Brown
Tried it, but same results, message box is not displayed until you move the mouse pointer so aero peek exits...And according to MSDN documentation, "An application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice."
Katana
You're right. Updated answer with another solution.
Eric Brown