Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Problem with windows shutdown (http://www.go4expert.com/forums/windows-shutdown-t8034/)

Metabaron 30Dec2007 03:00

Problem with windows shutdown
 
I'm having a hard time to handle the WM_QUERYENDSESSION and WM_ENDSESSION messages correctly.

I'm always ready to shutdown so I always return TRUE to WM_QUERYENDSESSION. In WM_ENDSESSION I perform some cleanup and then post the WM_QUIT message.

The problem with my code is that it will shutdown on WM_ENDSESSION and my process is cleanly terminated but for some reason my application interrupts the windows shutdown sequence and the system will not shutdown. The system will shutdown smoothly on the second attempt (when my process is already dead).

What am I doing wrong?

The code:
Code:

int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
...

// Main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg) ||
!IsDialogMessage(msg.hwnd,&msg) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}

static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_COMMAND:
if (LOWORD(wParam) == MTM_EXIT) {
CloseApp(hwndDlg,wParam,lParam);
PostQuitMessage(0);
return TRUE;
}
break;

case WM_QUERYENDSESSION:
return TRUE;

case WM_CLOSE:
case WM_ENDSESSION:
CloseApp(hwndDlg,wParam,lParam);
PostQuitMessage(0);
return TRUE;

...
}
}


Metabaron 1Jan2008 22:30

Re: Problem with windows shutdown
 
I found a solution and posted it into another forum:

http://www.codeguru.com/forum/showthread.php?t=442396


All times are GMT +5.5. The time now is 18:06.