GetMessage 正确用法

来源:互联网 发布:jquery 数组排序 编辑:程序博客网 时间:2024/05/16 01:35
 Warning  

Because the return value can be nonzero, zero, or -1, avoid code like this:

while (GetMessage( lpMsg, hWnd, 0, 0)) ...

The possibility of a -1 return value means that such code can lead to fatal application errors. Instead, use code like this:

Hide Example

BOOL bRet;while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0){     if (bRet == -1)    {        // handle the error and possibly exit    }    else    {        TranslateMessage(&msg);         DispatchMessage(&msg);     }}
原创粉丝点击