Message numbers in the fourth range 0xC through 0xFFFF are defined at run time when an application calls the RegisterWindowMessage function to retrieve a message number for a string.
All applications that register the same string can use the associated message number for exchanging messages. The actual message number, however, is not a constant and cannot be assumed to be the same between different sessions. Messages and Message Queues. Skip to main content. This browser is no longer supported.
Download Microsoft Edge More info. Contents Exit focus mode. Please rate your experience Yes No. In almost all cases, you will set these parameters to zero. Although the MSG structure contains information about the message, you will almost never examine this structure directly. Instead, you will pass it directly to two other functions.
The TranslateMessage function is related to keyboard input. It translates keystrokes key down, key up into characters. You do not really have to know how this function works; just remember to call it before DispatchMessage.
The link to the MSDN documentation will give you more information, if you are curious. The DispatchMessage function tells the operating system to call the window procedure of the window that is the target of the message.
In other words, the operating system looks up the window handle in its table of windows, finds the function pointer associated with the window, and invokes the function. When the window procedure returns, it returns back to DispatchMessage. This returns to the message loop for the next message. As long as your program is running, messages will continue to arrive on the queue. Therefore, you must have a loop that continually pulls messages from the queue and dispatches them.
You can think of the loop as doing the following:. As written, of course, this loop would never end. That is where the return value for the GetMessage function comes in. Normally, GetMessage returns a nonzero value. When you want to exit the application and break out of the message loop, call the PostQuitMessage function. Here is the revised message loop. As long as GetMessage returns a nonzero value, the expression in the while loop evaluates to true.
After you call PostQuitMessage , the expression becomes false and the program breaks out of the loop. Therefore, you do not have to have a case statement for this message in your window procedure.
The next obvious question is when to call PostQuitMessage. We'll return to this question in the topic Closing the Window , but first we have to write our window procedure. The previous section talked about messages going onto a queue. Sometimes, the operating system will call a window procedure directly, bypassing the queue. For now, the difference is not very important.
The window procedure handles all messages. However, some messages bypass the queue and go directly to your window procedure. However, it can make a difference if your application communicates between windows. You can find a more thorough discussion of this issue in the topic About Messages and Message Queues. Writing the Window Procedure. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info.
0コメント