79386072

Date: 2025-01-25 02:13:31
Score: 1.5
Natty:
Report link

The most common way to avoid code like while (GetMessage( lpMsg, hWnd, 0, 0)) is to use while (GetMessage(&msg, NULL, 0, 0))!

The possibility of a -1 return value in the case that hWnd is an invalid parameter (such as referring to a window that has already been destroyed) means that such code can lead to fatal application errors.

GetMessage return -1 means there is an error in the code you wrote. Please fix it. The most typical example is while (GetMessage( lpMsg, hWnd, 0, 0)) This can cause problems including, but not limited to, not being able to receive the WM_QUIT message to end the message loop. This directly causes GetMessage to return -1 after the window identified by hWnd is destroyed.

Checking whether GetMessage returns -1, like using at() on a vector, is unnecessary in a well-designed program.
Once you have written your code correctly, you don't have to worry about GetMessage returning -1.

For more details, see Raymond Chen's article
When will GetMessage return -1?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: 許恩嘉