项目中用到了好多这个消息循环,很是困惑。遂百度之,难道一个窗口下可以有多个消息循环吗?百度结果都是介绍和GetMessage区别的,正经的说这个有啥作用的,少之又少。不过有一篇英文的不错,这是出处,可以参考一下
http://blog.youkuaiyun.com/scofieldlau/article/details/1965517#t0
。奈何我的疑惑仍然为解。最后查看MSDN,清晰一二
原文
Unlike the GetMessage function, the PeekMessage function does not wait for a message to be placed in the queue before returning.
PeekMessage retrieves only messages associated with the window identified by thehWnd parameter or any of its children as specified by theIsChild function, and within the range of message values given by thewMsgFilterMin andwMsgFilterMax parameters. If hWnd is NULL,PeekMessage retrieves messages for any window that belongs to the current thread making the call. (PeekMessage does not retrieve messages for windows that belong to other threads.) IfhWnd is –1, PeekMessage only returns messages with ahWnd value of NULL, as posted by thePostThreadMessage function. IfwMsgFilterMin andwMsgFilterMax are both zero,PeekMessage returns all available messages (that is, no range filtering is performed).
The WM_KEYFIRST and WM_KEYLAST constants can be used as filter values to retrieve all keyboard messages; the WM_MOUSEFIRST and WM_MOUSELAST constants can be used to retrieve all mouse messages.
The PeekMessage function does not remove WM_PAINT messages from the queue. WM_PAINT messages remain in the queue until they are processed.
翻译
PeekMesssge只得到那些与参数hWnd标识的窗口相联系的消息或被lsChild确定为其子窗口相联系的消息,并且该消息要在由参数wMsgFiterMin和wMsgFiherMax确定的范围内。如果hWnd为NULL,则PeekMessage接收属于当前调用线程的窗口的消息(PeekMessage不接收属于其他线程的窗口的消息)。如果hWnd为-1,PeekMessage只返回hWnd值为NULL的消息,该消息由函数PostThreadMessage寄送。如果wMsgFilterMin和wMsgFilterMax都为零,PeekMessage返回所有可得的消息(即,无范围过滤)。