On Windows I get WM_CLOSE message which is handled by WndProc, which notifies application is being quit either through -
- User clicked cross(X) button
- User pressed Alt+F4 Keyboard shortcut
- User right click on application icon in taskbar and clicked "Close window"/"Close all windows"
- User went to Task Manager and from Applications tab, clicked on End Task
Before even WM_CLOSE, windows sends following message and we can use it to detect the above:
message=WM_SYSCOMMAND (WndProc) and wParam=SC_CLOSE and lParam != 0 implies "1." i.e. Cross(X) button
message=WM_SYSCOMMAND (WndProc) and wParam=SC_CLOSE and lParam = 0 implies "2.", "3." or "4."
Please note "2." can be detected by listening WM_SYSKEYDOWN and wParam = VK_F4 (received even before WM_SYSCOMMAND)
Now any idea how do I distinguish between "3." and "4." as well?
Ultimately I need to do something when my application is killed from applications tab in Task Manager.