根据MSDN Library中的
GetMessage API,当出现错误时它可能返回-1.该文档提供了应避免的常见错误的代码片段:
while (GetMessage( lpMsg,hWnd,0)) ...
文件说:
The possibility of a -1 return value
means that such code can lead to fatal
application errors. Instead,use code
like this:
BOOL bRet; while( (bRet = GetMessage( &msg,0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } }
我的问题是,在每个示例代码中,包括从Microsoft Visual Studio创建的默认应用程序,主消息循环如下所示:
while (GetMessage(&msg,NULL,0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
请注意,上面的GetMessage的第二个参数是NULL.如果上面的代码有效,这是否意味着此处的GetMessage将永远不会返回-1,因此不需要处理返回值-1?