Why does GetMessage not process WM_POWERBROADCAST messages?

偶尔善良 提交于 2019-12-07 22:53:30

问题


I'm creating a hidden window for the purpose of handling messages. I'm experiencing that I do not receive WM_POWERBROADCAST messages in it's GetMessage loop. I do, however, receive it via my WNDPROC. I have confirmed that I do receive other messages in both locations.

Why is GetMessage not receiving WM_POWERBROADCAST?

WNDCLASSEX classInfo = {0};
classInfo.cbSize = sizeof(classInfo);
classInfo.style = WS_DISABLED;
// CustomWndProc just outputs the message and chains to DefaultWndProc
classInfo.lpfnWndProc = CustomWndProc; 
classInfo.hInstance = GetModuleHandle(NULL);
classInfo.hCursor = NULL;
classInfo.hbrBackground = NULL;
classInfo.lpszMenuName = NULL;
classInfo.lpszClassName = L"MyMessageWindow";
ATOM windowClass = RegisterClassEx(&classInfo);

HWND messageWindow = CreateWindowEx(WS_EX_NOACTIVATE, L"MyMessageWindow", 
    L"Message Handling Window", WS_DISABLED, 0, 0, 0, 0, 0, NULL, 
    GetModuleHandle(NULL), NULL);

MSG message;
while (GetMessage(&message, NULL, 0, 0))
{
    // This condition is never true.
    if (message.message == WM_POWERBROADCAST)
        std::cout << "Got WM_POWERBROADCAST" << std::endl;
}

回答1:


That's because WM_POWERBROADCAST is a dispatched synchronously and so is not placed on the message queue.

In order for you to process it you need to handle it in your window procedure.



来源:https://stackoverflow.com/questions/20339124/why-does-getmessage-not-process-wm-powerbroadcast-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!