// 如果有消息,则响应并处理消息


BOOL CXXXDlg::PeekAndPump()
{
static MSG msg;
while(::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if(!AfxGetApp()->PumpMessage())
{
::PostQuitMessage(0);
return FALSE;
}
if(msg.message == WM_KEYDOWN && VK_ESCAPE == msg.wParam )
{
m_bDoCount=FALSE;
}
}
return TRUE;
}
// 每次循环先处理消息队列中的消息


void CXXXDlg::Loop()
{
while(

{
// 检查消息队列中的消息
PeekAndPump();
// do other work here

}
}