System shutdown behaviour?
-
I am responding to system shut down with the help of WM_QUERYENDSESSION but the problem is before i respond to this message some applications are being closed which are sitting in the Task bar tray and also some open applications in the task bar.I don't want this to happen.Is there any way to be the first in trapping WM_QUERYENDSESSION session and avoid other applications being killed.
-
I am responding to system shut down with the help of WM_QUERYENDSESSION but the problem is before i respond to this message some applications are being closed which are sitting in the Task bar tray and also some open applications in the task bar.I don't want this to happen.Is there any way to be the first in trapping WM_QUERYENDSESSION session and avoid other applications being killed.
You can intercept (and block) this message by installing a system-wide hook with
[SetWindowsHookEx](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/CommCtls/winui/hooks_7vaw.asp)
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
I am responding to system shut down with the help of WM_QUERYENDSESSION but the problem is before i respond to this message some applications are being closed which are sitting in the Task bar tray and also some open applications in the task bar.I don't want this to happen.Is there any way to be the first in trapping WM_QUERYENDSESSION session and avoid other applications being killed.
Below is the code snippet i used for HOOKING the WM_QUERYENDSESSION.But i never see the message box i am displaying. 1.Is there any problem with the below code 2.Also how can i discard the WM_QUERYENDSESSION at this moment so that it will not reach other applications. DLL_EXPORT void SetHook(void) { if(!bHooked) { hhook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)MsgProc, hInst, (DWORD)NULL); bHooked = TRUE; } } LRESULT CALLBACK MsgProc(int code, WPARAM wParam, LPARAM lParam) { MSG* msg; msg = (MSG*) lParam; if( code >= 0 ) { if( msg->message == WM_QUERYENDSESSION) { MessageBox( NULL , "Recieved WM_QUERYENDSESSION" , "test" , MB_OK|MB_APPLMODAL|MB_SETFOREGROUND|MB_TOPMOST ); } } return CallNextHookEx(hhook, code, wParam, lParam) ; }