为什么GetMessage无法处理WM_POWERBROADCAST消息? [英] Why does GetMessage not process WM_POWERBROADCAST messages?
问题描述
我正在创建一个用于处理消息的隐藏窗口.我遇到了我的GetMessage循环中没有收到WM_POWERBROADCAST消息的情况.但是,我确实通过WNDPROC收到了它.我已经确认我在这两个地方确实都收到了其他消息.
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.
为什么GetMessage没有收到WM_POWERBROADCAST?
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;
}
推荐答案
这是因为WM_POWERBROADCAST
是同步分派的,因此未放在消息队列中.
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.
这篇关于为什么GetMessage无法处理WM_POWERBROADCAST消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!