Windows消息队列何时创以及它与线程的关系

Windows系统存在系统消息队列和线程特定消息队列。线程在首次调用User或GDI函数时,系统为其创建消息队列。非GUI线程默认无消息队列,只有在特定函数调用后才会生成。
摘要由CSDN通过智能技术生成

面试的时候被问到一个程序会有几个消息队列,当时答错了。之后我找到了一些相关资料,现在记录一下。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值