a small problem with windows messages (SDK)
-
dear all, i've written a small piece of code ( a hidden window) which detects windows shutdown and then logs the timestamp in a file. i'm using the following code in the message loop- while(GetMessage(&Msg, hwnd, 0, 0) > 0) { if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } TranslateMessage(&Msg); DispatchMessage(&Msg); } now my wm_queryendsession handler is as follows case WM_QUERYENDSESSION: { if (lParam & ENDSESSION_LOGOFF) flg_type = 1; //logoff else flg_type = 2; //shut down flg_shutdown = 1; return false; // don't shutdown now. shutdown after Run() is executed } break; the problem is that when i logoff/shutdown nothing happens until i do something with the window (move cursor over it or click on it or resize it). when i do so, everything works fine. what could be the problem. i even tried the following message loop while(GetMessage(&Msg, hwnd, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } } but same problem. can someone help me out. Thanx and Regards
-
dear all, i've written a small piece of code ( a hidden window) which detects windows shutdown and then logs the timestamp in a file. i'm using the following code in the message loop- while(GetMessage(&Msg, hwnd, 0, 0) > 0) { if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } TranslateMessage(&Msg); DispatchMessage(&Msg); } now my wm_queryendsession handler is as follows case WM_QUERYENDSESSION: { if (lParam & ENDSESSION_LOGOFF) flg_type = 1; //logoff else flg_type = 2; //shut down flg_shutdown = 1; return false; // don't shutdown now. shutdown after Run() is executed } break; the problem is that when i logoff/shutdown nothing happens until i do something with the window (move cursor over it or click on it or resize it). when i do so, everything works fine. what could be the problem. i even tried the following message loop while(GetMessage(&Msg, hwnd, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); if (flg_shutdown == 1) { flg_shutdown = 0; Run(); //logs time stamp in a file ShutDown(); // shutsdown the system using ExitWindowsEx(...) } } but same problem. can someone help me out. Thanx and Regards
WM_QUERYENDSESSION is sent which means that it is not seen by the message loop. The code in the message loop will be executed the next time a message is posted to your window. Maybe you should move your code to the message handler. regards Oliver
-
WM_QUERYENDSESSION is sent which means that it is not seen by the message loop. The code in the message loop will be executed the next time a message is posted to your window. Maybe you should move your code to the message handler. regards Oliver
thanx for ur concern. i am executing the code when wm_queryendsession returns 0 (i.e. logoff or shutdown is aborted) if i try to run the code (starting an application for file write operation) in the messagehandler itself, i cannot execute the application because windows is shutting down. i also tried to send a message(wm_lbuttonup) in the loop, but still i can't make it work
-
thanx for ur concern. i am executing the code when wm_queryendsession returns 0 (i.e. logoff or shutdown is aborted) if i try to run the code (starting an application for file write operation) in the messagehandler itself, i cannot execute the application because windows is shutting down. i also tried to send a message(wm_lbuttonup) in the loop, but still i can't make it work
The problem is that the message loop does not get called when a message is sent to your handler. If you cannot perform your task in the message handler you have to make sure that the message loop is triggered without any user interaction. Maybe you coud post a message to your window, e.g.
PostMessage(hYourWindow, WM_NULL, NULL, NULL);
This will trigger the message loop some time after your handler has finished. regards Oliver