• 0

Not caught: WM_QUERYENDSESSION and WM_ENDSESSION


Question

Hey guys, I'm trying to catch WM_QUERYENDSESSION and WM_ENDSESSION to no avail. I'm creating a window like so:

WNDCLASSEX wcex;
	 LPCTSTR wname;

	 wname = TEXT("ASInvisWin");

	 wcex.cbSize = sizeof(wcex);
	 wcex.style = 0;
	 wcex.lpfnWndProc = invisible_window_msg_handler;
	 wcex.cbClsExtra = 0;
	 wcex.cbWndExtra = 0;
	 wcex.hInstance = hinstance;
	 wcex.hIcon = NULL;
	 wcex.hCursor = NULL;
	 wcex.hbrBackground = NULL;
	 wcex.lpszMenuName = NULL;
	 wcex.lpszClassName	= wname;
	 wcex.hIconSm = NULL;

	 RegisterClassEx(&wcex);

	 /* Create the window */
	 systray_hwnd = CreateWindow(wname, "", WS_OVERLAPPED, 0, 0, 0, 0, GetDesktopWindow(), NULL, hinstance, 0);

Here's the function that should catch it:

LRESULT CALLBACK invisible_window_msg_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {

	 switch (msg) {

	 case WM_QUERYENDSESSION: {

	  /* Okay, the session is about to end! */
	  printf("waiting...\n");
	  sleep(3500);
	  printf("done!\n");
	  return 0;
	 }

}

It doesn't get caught, and when I logoff or shutdown, none of the messages print. I read somewhere it has to be a toplevel window for it to get caught... shouldn't WS_OVERLAPPED do the trick?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Fixed. It seems I was compiling the program as a console application, and even though there was a UI involved, Windows won't send those messages. Compiling it as a GUI application solved the problem. :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.