gpt4 book ai didi

windows - WM_PAINT 消息是排队消息还是非排队消息?

转载 作者:可可西里 更新时间:2023-11-01 11:28:59 26 4
gpt4 key购买 nike

在这篇文章中About Messages and Message Queues ,据说 WM_PAINT 是一种排队消息。

排队的消息

Whenever the user moves the mouse, clicks the mouse buttons, or typeson the keyboard, the device driver for the mouse or keyboard convertsthe input into messages and places them in the system message queue.The system removes the messages, one at a time, from the systemmessage queue, examines them to determine the destination window, andthen posts them to the message queue of the thread that created thedestination window. A thread's message queue receives all mouse andkeyboard messages for the windows created by the thread. The threadremoves messages from its queue and directs the system to send them tothe appropriate window procedure for processing.

With the exception of the WM_PAINT message, the WM_TIMER message, and the WM_QUIT message,the system always posts messages at the end of a message queue. Thisensures that a window receives its input messages in the proper firstin, first out (FIFO) sequence. The WM_PAINT message, the WM_TIMERmessage, and the WM_QUIT message, however, are kept in the queue andare forwarded to the window procedure only when the queue contains noother messages. In addition, multiple WM_PAINT messages for the samewindow are combined into a single WM_PAINT message, consolidating allinvalid parts of the client area into a single area. CombiningWM_PAINT messages reduces the number of times a window must redraw thecontents of its client area.

但是根据《programming windows》这本书

However, the window procedure could call a function that sends thewindow procedure another message, in which case the window proceduremust finish processing the second message before the function callreturns, at which time the window procedure proceeds with the originalmessage. For example, when a window procedure calls UpdateWindow,Windows calls the window procedure with a WM_PAINT message. When thewindow procedure finishes processing the WM_PAINT message, theUpdateWindowcall will return controls back to the window procedure.

如果WM_PAINT 是排队的消息,它应该被添加到消息队列中。因此在处理完当前消息和消息队列中的所有其他消息之前,它不会处理。这与上述说法存在争议。

我想知道哪个是正确的,谢谢。

最佳答案

任何消息都可以使用 SendMessage 直接发送到窗口过程,或者使用 PostMessage 发送到窗口的消息队列。 UpdateWindow 函数使用 SendMessageWM_PAINT 消息直接发送到窗口过程,以便立即重绘窗口。当系统出于任何原因需要重新绘制窗口时,它通常会将消息发布到窗口的消息队列中。

因此 WM_PAINT 不是排队(发布)的消息,也不是已发送的消息。这只是一条消息。它可以发送或邮寄。有些消息仅用于发送或发布,但 WM_PAINT 不是其中之一。

关于windows - WM_PAINT 消息是排队消息还是非排队消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25713183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com