I am using Visual Studio 2005 with MFC and Windows 7. I have an application with many dialog windows.
I use OnSysCommand to check for SC_CLOSE messages and check the lParam to determine if this is initiated from the task bar or the close button on the dialog. But how can I determine whether a close message is a "close all windows" from the task bar or just closing an individual dialog from the task bar?
Thanks
I don't think that you get this solved with a single message.
When you Close the application you have to distinguish also between a mouse action and Alt+F4
If you close the application with Alt+F4 the message looks identical like closing it from the task bar (Look at the lParam value)
You can look at the last message that was retrieved with GetMessage (the last input message). If the message comes from the task bar it is a posted WM_SYSCOMMAND. If the message comes from the inside you receive the WM_SYSCOMMAND as SendMessage.
You can use AfxGetCurrentMessage to determine what was the last input message. If you find WM_SYSCOMMAND here the close comes from the taskbar. If you find a keyboard or mouse message here the message comes form the user input.
Tip: Use Spy++ to examine this behavior.
I think you can differentiate as follows:
Closing a windows using the system menu 'Close' generates a WM_SYSCOMMAND where wParam= SC_CLOSE and lParam!=0.
Closing the window using Alt+F4 or "Close all windows" both generate a WM_SYSCOMMAND with a wParam=SC_CLOSE and lParam=0.
However, Alt+F4 generates a WM_SYSKEYDOWN message with wParam=VK_F4 beforehand.
I wanted to ignore the "Close all windows", whilst using Alt+F4 and the 'Close' menu. I therefore caught Alt+F4 in WM_SYSKEYDOWN and posted a WM_CLOSE message. I then ignored any WM_SYSCOMMAND message with wParam=SC_CLOSE and lParam=0.