区别一:
peekmessage不管消息队列里有没有消息都会马上返回,有消息返回消息,没消息返回空值,
getmessage等待到有消息的时候才返回,
区别二:
peekmessage可以根据参数决定是否将消息保留在队列中,
PM_NOREMOVE:该参数指示保留消息
PM_REMOVE:该参数指示移去消息
而getmessage获得消息后回把消息从消息队列中删去
例程:
// GetMessage Damo
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine,
int iCmdShow)
{
MSG msg ;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return TRUE ;
}
// PeekMessage() Damo
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine,
int iCmdShow)
{
MSG msg ;
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return TRUE ;
}
peekmessage,getmessage区别
最新推荐文章于 2014-02-17 13:45:00 发布