C++ 清空消息队列

在按钮等被禁用后,可能需要它在禁用期间不去响应任何消息。

可以使用下面的语句片段:

MSG msg; 

//消耗掉消息队列中的所有消息
while(::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//WM_PAINT不能被REMOVE,需要Dispatch
if (msg.message=WM_PAINT)
{
::DispatchMessage(
&msg);
}
}

  

posted @ 2011-01-18 22:21  OYJJ  阅读(2775)  评论(0编辑  收藏  举报