| int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPCTSTR lpCmdLine, int nCmdShow) { MSG msg; ... while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } ... return (int)msg.wParam; } |
| http://msdn.microsoft.com/ library/ en-us/ winui/ winui/ windowsuserinterface/ windowing/ messagesandmessagequeues/ messagesandmessagequeuesreference/ messagesandmessagequeuesfunctions/ getmessage.asp >Return Value >If the function retrieves a message other than WM_QUIT, the return value is nonzero. >If the function retrieves the WM_QUIT message, the return value is zero. >If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError. >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: BOOL bRet; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } } |
| while (GetMessage( lpMsg, hWnd, 0, 0)) ... |
| BOOL bRet; while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } } |