仅消息窗口可以接收 WM_QUERYENDSESSION 吗? [英] Can a message-only window receive WM_QUERYENDSESSION?
问题描述
在程序的调试版本中,我创建了一个可见窗口,WNDPROC
收到了WM_QUERYENDSESSION
消息.在发布版本中,窗口应该是仅消息的,因此我在调用 CreateWindowEx()
时将 HWND_MESSAGE
指定为 hWndParent
.不幸的是,我不再收到 WM_QUERYENDSESSION
消息.WM_QUERYENDSESSION
是这里?仅消息窗口 [...] 不接收广播消息."
In the debug version of the program, I create a visible window, and the WM_QUERYENDSESSION
message is received by the WNDPROC
. In the release version, the window is supposed to be message-only, so I specify HWND_MESSAGE
as the hWndParent
when calling CreateWindowEx()
. Unfortunately, I then don't receive the WM_QUERYENDSESSION
message anymore. Is WM_QUERYENDSESSION
one of those broadcast messages mentioned here? "A message-only window [...] does not receive broadcast messages."
推荐答案
MSDN 给出了仅消息窗口"的正确定义:
MSDN gives a decent definition of a "message-only window":
仅消息窗口使您能够发送和接收消息.它不可见,没有 z 顺序,无法枚举,并且不接收广播消息.窗口只是发送消息.
A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.
突出显示相关细节.
您可以使用它们在自己的代码中利用消息分发机制.最常见的是让工作线程以线程安全的方式与 UI 线程对话.消息循环是生产者-消费者问题的通用解决方案.例如,COM 中的单元封送处理是使用仅消息窗口实现的.显然,这样的窗口应该被隐藏,并且只能获取应用定义的消息.
You use them to take advantage of the message dispatch mechanism in your own code. Most typically to get a worker thread to talk to the UI thread in a thread-safe way. A message loop is the universal solution to the producer-consumer problem. Apartment marshaling in COM is implemented with a message-only window for example. Clearly such a window should be hidden and only get the messages that are defined by the app.
在调用 CreateWindowEx 时不要使用 HWND_MESSAGE 作为 hWndParent.
Don't use HWND_MESSAGE as hWndParent when calling CreateWindowEx.
这篇关于仅消息窗口可以接收 WM_QUERYENDSESSION 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!