Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

winapi - Can a message-only window receive 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."

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

MSDN gives a decent definition of a "message-only window":

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.

Relevant detail highlighted.

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.

Don't use HWND_MESSAGE as hWndParent when calling CreateWindowEx.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...