How can I distinguish between “Close all windows” and “Close” individual windows in MFC with Windows 7?

I am using Visual Studio 2005 with MFC and Windows 7. I have an application with many dialog boxes.

I use OnSysCommand to check SC_CLOSE messages and check lParam to determine if it is triggered from the taskbar or close button in the dialog box. But how can I determine if a closed “close all windows” message from the taskbar closes or just closes a separate dialog in the taskbar?

thanks

+1
source share
2 answers

I do not think that you solve this with a single message.

When closing the application, you must also distinguish between mouse action and Alt + F4. If you close the application using Alt + F4, the message looks the same as closing it from the taskbar (see lParam value)

You can see the last message that was received using GetMessage (the last input message). If the message appears on the taskbar, this message is WM_SYSCOMMAND. If the message comes from within, you get WM_SYSCOMMAND as SendMessage.

You can use AfxGetCurrentMessage to determine what was the last input message. If you find WM_SYSCOMMAND here, then the closure comes from the taskbar. If you find here a message with a keyboard or mouse, the message comes from user input.

Tip. Use Spy ++ to learn this behavior.

+2
source

I think you can distinguish the following:

Closing windows using the Close system menu creates WM_SYSCOMMAND, where wParam = SC_CLOSE and lParam! = 0.

Closing a window using Alt + F4 or "Close all windows" generates WM_SYSCOMMAND using wParam = SC_CLOSE and lParam = 0.

However, Alt + F4 generates a WM_SYSKEYDOWN message with wParam = VK_F4 in advance.

I wanted to ignore Close All Windows using Alt + F4 and Close. So I caught Alt + F4 in WM_SYSKEYDOWN and sent a WM_CLOSE message. Then I ignored any WM_SYSCOMMAND message with wParam = SC_CLOSE and lParam = 0.

0
source

All Articles