I read in here that WM_POWERBROADCAST messages should be processed inside WindowProc. I tried to capture WM_POWERBROADCAST without a message loop and was not successful. Following is what I tried:
static long FAR PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_POWERBROADCAST)
{
if (wParam == PBT_APMSUSPEND )
std::cout << "PBT_APMSUSPEND\n";
if ( wParam == PBT_APMRESUMESUSPEND )
std::cout << "PBT_APMRESUMESUSPEND\n";
return TRUE;
}
else
return DefWindowProc(hWnd, message, wParam, lParam);
}
int main(int argc, char* argv[])
{
WNDCLASS wc = {0};
// Set up and register window class
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = L"SomeNameYouInvented";
RegisterClass(&wc);
HWND hWin = CreateWindow(L"SomeNameYouInvented", L"", 0, 0, 0, 0, 0, NULL, NULL, NULL, 0);
while(True);
return 0;
}
Can someone tell me what I am doing wrong or is it even possible to do it without message loop? In case it is not possible without a message loop how is queued and non queued messages different in this aspect.