面试的时候被问到一个程序会有几个消息队列,当时答错了。之后我找到了一些相关资料,现在记录一下。
The system maintains a single system message queue and one thread-specific message queue for each GUI thread. To avoid the overhead of creating a message queue for non–GUI threads, all threads are created initially without a message queue. The system creates a thread-specific message queue only when the thread makes its first call to one of the specific user functions; no GUI function calls result in the creation of a message queue.
摘自https://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx
可以知道系统有两类消息队列,一个是系统消息队列,一种是线程的消息队列。消息会首先进入系统消息队列,然后再从系统消息队列中取出,分配到线程的消息队列中。
引用的下半部分写了,当一个线程调用一个特殊User函数(有的博客写到来自user32.dll,这个没有查到)的时候,系统就会为它创建消息队列。最后的”no GUI function cal