WIN32API message mechanism
- What is a message under the Windows platform?
- When the system notifies the window to work, it sends the window processing function to the window using the message.
- Message consists of 6 large parts combinations, which are indispensable:
- 1 Window Handle
- Every Win32 window program, as long as there is a window, it is impossible to have no window handle, because the creation of the beginning of the handle, as if the car to the road on the mandatory requirements of a "license plate."
- 2 Message ID
- Microsoft gives Windows message mechanism, design 1024 message number, this kind of number appears, represent this kind of message appearance.
- 3 Message two parameters (with information)
- Any message comes with two messages: 1 different messages, the two accompanying information are different 21 are saved with wparam, and the other one is saved with the lparam type.
- 4 The time the message was generated (not paying attention, but indispensable)
- 5 mouse position at the time of message generation (not attention, but indispensable)
- Message-related functions
- 1 GetMessage-Get the message for this process
BOOL GetMessage (
Lpmsg lpmsg,//store gets to the message buff
HWND hwnd,//Window handle
UINT wmsgfiltermin,//Gets the minimum ID of the message default 0
UINT Wmsgfiltermax//Gets the maximum ID of the message by default 0
);
- Lpmsg lpmsg,-when the message is obtained, the parameters of the message are stored in the MSG structure.
- HWND hwnd,-Gets the message of the window specified by the HWND.
- Unit Wmsgfiltermin and unit Wmsgfiltermax-can only get messages within the range of messages specified by them, if both are 0, indicating no range.
- BOOL GetMessage (...) The return value of this function is very important.
- while (GetMessage (...)) {......} Returns 0 to end, but only one message that can make the GetMessage function return 0: Wm_quit.
- PostQuitMessage (0); A wm_quit message is preset. # #助记: Dig a hole to bury mine
- 2 TranslateMessage-Translate the message. The search message is translated into a character message.
BOOL TranslateMessage (
Const msg* LPMSG//message address to translate
);
- Check that the message is not a keystroke message, not a keystroke message, do not do any processing, continue execution.
- 3 DispatchMessage-Distribute the message.
LONG DispatchMessage (
Const msg* LPMSG
);
- The DispatchMessage (&msg,null,null,null) function dispatches the message, triggers the window handler function, and invokes the window handler function.
- Msg.hwnd--Find memory to save window data---> Compare window name---> match window class---> Call WndProc (Msg.hwnd, Msg.message, Msg,wparam, Msg.lparam); ---> gives us the opportunity to process the message, we only deal with the messages we care about, the rest of the message, and let the system default function DefWindowProc ().
WIN32API message mechanism