GetMessage returns 1 when an error is encountered, even if its return value is defined as bool. Because bool is defined as UINT.
The correct notation for calling GetMessage is while (GetMessage (&msg, NULL, 0, 0) > 0), which correctly handles the error of the function and the exit of the program.
You can use PostMessage or SendMessage to send messages. PostMessage the message into the message queue and returns immediately. This means that the message may or may not have been processed after you call PostMessage. SendMessage the message to the window and does not return until the window has finished processing the message.
Modal dialogs There are some important differences between the process and the window process, where the first 2nd also applies to the Non modal dialog box.
- Do not call DefWindowProc () for messages that you do not process. This is done automatically in the dialog box, and you will have a problem if you really want to call it yourself.
- Returns true for unhandled messages that return false.
- Do not call DestroyWindow to close a dialog box, and call EndDialog ().
- Do not handle wm_create, instead, handle the WM_INITDIALOG message to do any action before the dialog box appears.
With Createdialog, you can create a non-modal dialog box that does not have its own message loop. DialogBox () has its own message loop and returns until the dialog box is closed.
The non-modal dialog procedure does not need to call EndDialog and can call DestroyWindow like a regular window.
A dialog box is a window, and most of the dialog's APIs can work in any window.
www.winprog.org Reading notes