GetMessage(&msg,NULL,0,0)和GetMessage(&msg,hwnd,0,0)


如果是下面的hwnd,则当窗口关闭后,hwnd无效了,无法捕获WM_QUIT消息了。

while(GetMessage(&msg,hwnd,0,0))

{
TranslateMessage(&msg);
DispatchMessage(&msg);

}

hWnd
[in] Handle to the window whose messages are to be retrieved. The window must belong to the calling thread. The following value has a special meaning.
ValueMeaning
NULLGetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread using thePostThreadMessage function.


         参数hwnd设置为NULL,具有特殊的含义,GetMessage 会获取线程中的所有窗口的消息,以及通过PostThreadMessage投递的消息。


After  you receive the message WM_DESTROY and the window is destroyed. but your process will not quit until you get a WM_QUIT message, if you use hwnd to GetMessage,that means you only receive msg that belong that window,but the window has destroyed,so you can not receive the WM_QUIT message.


当接受到WM_DESTROY消息后,销毁窗口,但是进程不会退出,直到收到了WM_QUIT消息。如果GetMessage的参数是hwnd,那么只接受属于这个窗口的消息,当窗口销毁后,不能接受WM_QUIT消息,程序永远不会退出。



正确的用法是

while(GetMessage(&msg,NULL,0,0))

{
TranslateMessage(&msg);
DispatchMessage(&msg);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值