A WIN32 message mechanism
1 message mechanism
Process-driven: programs are executed in the order that we pre-defined them, and each step is executed in a predetermined order until the end of the program
Event-driven: The order in which programs are executed is unordered. The code executed by an event point is notified by the outside world. Code execution is unordered because we cannot determine the order of user execution
WIN32 message mechanism-event driven
2 WIN32 Message Program
2.1 Win32 Window Registration
2.2 Win32 Window creation
2.3 Win32 message loop
2.3.1 GetMessage
BOOL GetMessage ( lpmsg lpmsg, //Message information holds the data retrieved to the HWND hWnd, ///Handle to window handle for the Windows handle of the message UINT wmsgfiltermin, Start message for the //First message Filter
UINT wmsgfiltermax //Last message message filtering for terminating messages
);
Return value: The successful Get message returns TRUE, but returns false when the Wm_quit message is obtained
PostQuitMessage: Send a WM_QUIT message
MSG-The system fills in the parameters about the message
Hwnd-getmessage receives a message from the window specified by the HWND, based on the HWND value
Wmsgfiltermin Wmsgfiltermax-Message Filter requires GetMessage to receive a specified range of messages
2.3.2 DispatchMessage
LRESULT dispatchmessage ( CONST MSG*lpmsg //message information);
According to the window handle inside the message data, find the message handler function of this window, call the function, do the message processing, if the HWND in the message structure is NULL, will not do any processing
2.3.3 TranslateMessage
BOOL translatemessage ( CONST MSG*lpmsg //message information );
Convert keyboard messages to character messages
1, first check whether it is a keyboard key message
2. If the key message is found, a character message will be generated according to the key, and a character message will be received when the next GetMessage executes.
3, if not found the key message, do not do any processing
2.4 Win32 Basic Message
2.4.1 Wm_destroy:: Window destroyed when the message can be done to exit or aftercare processing
2.4.2 wm_create: Window creates a message, which is the first message received by the window handler after the window is created, which can be used to initialize the data/create sub-windows within the message.
2.4.3 Wm_size: This message is received when the window size changes. You can adjust the layout of the window in this message
Wparam-size When a change occurs
LoWord (LParam) The width of the customer area
HiWord (LParam) customer area of the high
2.4.4 wm_syscommand: System command message, when you click on the System menu and button will receive this message, you can re-message, prompting the user to save data and so on.
WParam system Command Type
LoWord (LParam) mouse x coordinate
HiWord (LParam) mouse y-coordinate
2.4.5 Wm_activeapp: Application activation
2.4.6 WM_PAINT Drawing messages
2.4.7 Keyboard messages
2.4.8 keyboard messages
2.4.9 Wm_timer Timer Message
2.5 Message Structure
MSG-Message structure
typedef struct TAGMSG { HWND ///message occurrence window UINT //Message ID //Message Parameters //message parameter DWORD //message occurs at the time point