I am looking for a way to watch for specific messages sent by the system to my application. For example, I want to be able to watch for the WM_QUERYENDSESSION message and when it is received, to perform a specific action.

I am working with the python win32 extensions, but I'm sure that I could translate the equivalent code in another language.

I know how to use SendMessage to send messages to other windows, but I don't know what to use to watch for messages sent to my window.

Any help is appreciated.

in c++ you would go:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		    case WM_QUERYENDSESSION:
                    {
                        //the action to use when it receives this message
                    }
		}
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

hope that helps :)

Here's a nice thread about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.