Started code for handling WM_QUERYENDSESSION and its console equivalent.

This commit is contained in:
Pietro Gagliardi 2015-05-09 14:22:51 -04:00
parent 03cf0845ef
commit bd4716c949
3 changed files with 32 additions and 0 deletions

View File

@ -243,6 +243,19 @@ static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
logLastError("error getting client rect for resize in containerWndProc()");
resize(cc, &r);
return 0;
// and this is run only on the initial parent
// this ensures that all end session handling is done in one place and only once
case WM_QUERYENDSESSION:
case msgConsoleEndSession:
if (cc != NULL)
break;
// TODO block handler
if (shouldQuit()) {
uiQuit();
return TRUE;
}
return FALSE;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);

View File

@ -52,6 +52,19 @@ static const char *loadLastError(const char *message)
return str;
}
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
switch (dwCtrlType) {
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
// the handler is run in a separate thread
SendMessageW(initialParent, msgConsoleEndSession, 0, 0);
// we handled it here
return TRUE;
}
return FALSE;
}
uiInitOptions options;
const char *uiInit(uiInitOptions *o)
@ -98,6 +111,9 @@ const char *uiInit(uiInitOptions *o)
if (ce != NULL)
return loadLastError(ce);
if (SetConsoleCtrlHandler(consoleCtrlHandler, TRUE) == 0)
return loadLastError("setting up console end session handler");
hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH);
if (hollowBrush == NULL)
return loadLastError("getting hollow brush");
@ -109,6 +125,8 @@ void uiUninit(void)
{
uninitMenus();
// TODO delete hollow brush
if (SetConsoleCtrlHandler(consoleCtrlHandler, FALSE) == 0)
logLastError("unregistering console end session handler");
uninitContainer();
if (DeleteObject(hMessageFont) == 0)
logLastError("error deleting control font in uiUninit()");

View File

@ -36,6 +36,7 @@ enum {
msgNOTIFY,
msgUpdateChild, // fake because Windows seems to SWP_NOSIZE MoveWindow()s and SetWindowPos()s that don't change the window size (even if SWP_NOSIZE isn't specified)
msgHasTabStops,
msgConsoleEndSession,
};
// debug.c