一般的问题是,如果我从一个单独的工作线程向 Windows 消息泵发送多条消息,它们会按照我发送的顺序出现在目的地吗?即..
::PostMessage(m_hUsers, WM_BULKPROCESS, 0, 0);
// ... some processing here ...
::PostMessage(m_hUsers, WM_BULKDONE, 0, 0);
m_hUsers 是我从我的工作线程向其发送消息的窗口的句柄 (HWND)。那么,WM_BULKPROCESS 是否总是首先出现在窗口中(因此由该对话框类中的处理程序处理),或者它们是否有可能乱序,即 WM_BULKDONE 在 WM_BULKPROCESS 之前得到处理,即使它是最后发送的?
最佳答案
有一些异常(exception)(如 WM_PAINT),但一般来说,消息的顺序是保持不变的。 如果消息以错误的顺序出现,试图理解鼠标输入的图像!
引用自 GetMessage
During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, or SendNotifyMessage function. Then the first queued message that matches the specified filter is retrieved. The system may also process internal events. If no filter is specified, messages are processed in the following order:
Sent messages Posted messages Input (hardware) messages and system internal events Sent messages (again) WM_PAINT messages WM_TIMER messages
关于windows - PostMessage() 消息在 Windows 中是否按顺序显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7435696/