I have an application that I would like to close gracefully when Windows shuts down (or the user shuts down). It was used for work (in xp), but sometime last year it broke and no one noticed. It also broke (but in a different way) under Windows 7.
Our product has a main process (server.exe) that runs many other processes. The graceful shutdown of server.exe causes the entire process, which it begins to close. However, when I debug this code, it seems that the other processes are already completed. Our main process (server.exe) is the only process that processes WM_QUERYENDSESSION and WM_ENDSESSION messages. The code below (this is used to work under XP, but no longer exists):
LRESULT CALLBACK master_wnd_proc
(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
LRESULT result;
long msg_code;
switch (uMsg)
{
case WM_ENDSESSION:
if (wParam)
{
msg_code = PCS_WINDOWS_SHUTDOWN;
if( lParam & 0x01L )
msg_code = WINDOWS_SHUT_CLOSE;
if( lParam & 0x40000000L )
msg_code = WINDOWS_SHUT_CRIT;
if( (unsigned long)lParam & 0x80000000 )
msg_code = WINDOWS_SHUT_LOGOFF;
MsgGenerate(msg_code, MSG_SEVERE, MSG_LOG, "");
ipc_declare_shutdown( msg_code );
PostQuitMessage(EXIT_SUCCESS);
}
result = 0;
break;
case WM_QUERYENDSESSION:
result = TRUE;
break;
case WM_TIMER:
case WM_APP_IPC_POSTED:
(void) server();
result = FALSE;
break;
default:
result = DefWindowProc (hwnd, uMsg, wParam, lParam);
break;
}
return result;
}
, - , WM_QUERYENDSESSION ( ). , , .
Windows 7 API, , XP, , .
?