S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

MSDN 中的 MessageLoop

Posted on 2009-05-01 22:00 S.l.e!ep.¢% 阅读(317) 评论(0)  编辑 收藏 引用 所属分类: MulThreads

int MessageLoop (
HANDLE* lphObjects, // handles that need to be waited on
int cObjects // number of handles to wait on
)
{
// The message loop lasts until we get a WM_QUIT message,
// upon which we shall return from the function.
while (TRUE)
{
// block-local variable
DWORD result ;
MSG msg ;

// Read all of the messages in this next loop,
// removing each message as we read it.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// If it is a quit message, exit.
if (msg.message == WM_QUIT)
return 1;
// Otherwise, dispatch the message.
DispatchMessage(&msg);
} // End of PeekMessage while loop.

// Wait for any message sent or posted to this queue
// or for one of the passed handles be set to signaled.
result = MsgWaitForMultipleObjects(cObjects, lphObjects,
FALSE, INFINITE, QS_ALLINPUT);

// The result tells us the type of event we have.
if (result == (WAIT_OBJECT_0 cObjects))
{
// New messages have arrived.
// Continue to the top of the always while loop to
// dispatch them and resume waiting.
continue;
}
else
{
// One of the handles became signaled.
DoStuff (result - WAIT_OBJECT_0) ;
} // End of else clause.
} // End of the always while loop.
} // End of function.

 


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理