Event handler WinProc

Source: Internet
Author: User

The event handler is a callback function that is called in the main time loop when Windows has an event that needs to be handled in the form. The time-processing function handles whatever event you want to handle, and other events are passed to Windows for processing.
When users and Windows run certain actions, events and messages for some of the pin applications are generated, all of which go into a queue, and events and messages for an application form are transferred from the message queue to the private queue of the form.

The main event loop then fetches the messages and sends them to the form's winproc for processing.


The prototype of the message handler function is:

LRESULT CALLBACK WindowProc (HWND hwnd,//The form handle of the sender UINT msg,//message ID, that is, the kind of message wparam wparam,//specific information lparam lparam);//Specific information


WinProc knows from which form the message comes from, and MSG is the kind of message. Here are all the messages in Windows:
Wm_null = $0000;
Wm_create = $0001;
Application to create a form
Wm_destroy = $0002;
A form is destroyed
Wm_move = $0003;
Move a form
Wm_size = $0005;
Change the size of a form
Wm_activate = $0006;
A form is activated or inactive;
Wm_setfocus = $0007;
After gaining focus
Wm_killfocus = $0008;
Lose focus
wm_enable = $000a;
Change the Enable state
Wm_setredraw = $000b;
Set whether a form can be redrawn
Wm_settext = $000c;
The application sends this message to set the text of a form
Wm_gettext = $000d;
The application sends this message to copy the text of the corresponding form to the buffer
Wm_gettextlength = $000e;
Gets the length of the text associated with a form (excluding null characters)
WM_PAINT = $000f;
Require a form to repaint itself
Wm_close = $0010;
Send a signal when a form or application is about to close
Wm_queryendsession = $0011;
When the user chooses the End dialog box or the program calls the ExitWindows function itself
Wm_quit = $0012;
Used to end program execution or when a program calls the PostQuitMessage function
Wm_queryopen = $0013;
When the user form is restored to its previous size position. Send this message to an icon
WM_ERASEBKGND = $0014;
When the form background must be erased (example when the form changes size)
Wm_syscolorchange = $0015;
Send this message to all top-level forms when the system color changes
Wm_endsession = $0016;
When the system process issues a wm_queryendsession message. This message is sent to the application,
Tell it whether the conversation is over
Wm_systemerror = $0017;
Wm_showwindow = $0018;
When the hidden or displayed form is sent this message to this form
Wm_activateapp = $001c;
Send this message to the application which form is active and which is inactive;
Wm_fontchange = $001d;
Send this message to all top-level forms when the system's font repository changes
Wm_timechange = $001e;
Send this message to all top-level forms when the system's time changes
Wm_cancelmode = $001f;
Send this message to cancel an in-progress state (operation)
Wm_setcursor = $0020;
If the mouse causes the cursor to move through a form and the mouse input is not captured, a message is sent to a form
Wm_mouseactivate = $0021;
When the cursor is in a non-activated form and the user is pressing a key on the mouse to send the message to the current form
Wm_childactivate = $0022;
Send this message to the MDI child form when the user taps the title bar of this form. Or when the form is activated. Move, change the size
Wm_queuesync = $0023;
This message is sent by a computer-based training program, via the Wh_journalpalyback hook program
Separating out user input messages
Wm_getminmaxinfo = $0024;
This message is sent to the form when it is going to change size or position;
Wm_painticon = $0026;
Send to minimized form when its icon is going to be redrawn
Wm_iconerasebkgnd = $0027;
This message is sent to a minimized form only if it's background must be redrawn before the icon is drawn
Wm_nextdlgctl = $0028;
Send this message to a dialog box program to change the focus position
Wm_spoolerstatus = $002a;
This message is emitted whenever a job is added or lowered by a print management queue
Wm_drawitem = $002b;
When the button. Combobox,listbox,menu visual appearance changes when sending
This message is given to all of these empty pieces
Wm_measureitem = $002c;
When button, combo box, list box, List View control, or menu item is created
Send this message to all the people of the control
Wm_deleteitem = $002d;
When the list box or combo box is destroyed or when certain items are deleted through lb_deletestring, lb_resetcontent, cb_deletestring, or cb_resetcontent messages
Wm_vkeytoitem = $002e;
This message has a lbs_wantkeyboardinput style that is emitted to all of its people in response to the WM_KEYDOWN message
Wm_chartoitem = $002f;
This message is sent by a lbs_wantkeyboardinput-style list box to all of his people in response to the WM_CHAR message
Wm_setfont = $0030;
The program sends this message when the text is drawn to get the color of the control to be used
Wm_getfont = $0031;
The application sends this message to get the font of the current control drawing text
Wm_sethotkey = $0032;
The application sends this message to have a form associated with a hotkey
Wm_gethotkey = $0033;
The application sends this message to infer whether a hotkey is associated with a form
Wm_querydragicon = $0037;
This message is sent to the minimized form. When this form is about to be dragged and the icon is not defined in its class, the application can return an icon or a handle to the cursor, which is displayed when the user drags and puts the icon
Wm_compareitem = $0039;
Send this message to determine the relative position of the newly added item in the ComboBox or ListBox
Wm_getobject = $003d;
wm_compacting = $0041;
There's very little memory in the display.
wm_windowposchanging = $0046;
Send this message to the size and position of the form when it will be changed. To invoke the SetWindowPos function or other form management functions
wm_windowposchanged = $0047;
Send this message to the size and position of the form when it has been changed. To invoke the SetWindowPos function or other form management functions
Wm_power = $0048; (for 16-bit Windows)
This message is sent when the system is about to enter a paused state
Wm_copydata = $004a;
Send this message when an application passes data to another application
Wm_canceljournal = $004b;
When a user cancels the program Log activation state, the message is submitted to the program
Wm_notify = $004e;
When an event of a control has already occurred or the control needs to get some information. Send this message to its parent form
Wm_inputlangchangerequest = $0050;
When the user selects an input language. Or the hotkey change of the input language
Wm_inputlangchange = $0051;
Send this message to the affected top-level form when the platform field has been changed
Wm_tcard = $0052;
Send this message to the application when the program has initialized the Windows Help routine
Wm_help = $0053;
This message indicates that the user pressed the F1. If a menu is active, send this message a menu associated with this form. Otherwise,
Sent to the focused form, assuming there is currently no focus. This message is sent to the currently active form
wm_userchanged = $0054;
Send this message to all forms when the user has logged in or exited. When users log in or exit the system updates the user's details
Setting information that the system sends this message immediately when the user updates the settings.
Wm_notifyformat = $0055;
Common controls, which define their own controls and their parent forms, use this message to infer whether the control is using an ANSI or Unicode structure
In WM_NOTIFY messages, use this control to communicate with each other between a control and its parent control
Wm_contextmenu = $007b;
Send this message to this form when the user clicks the right button on a form
wm_stylechanging = $007c;
When calling the SetWindowLong function to change the style of one or more forms, send this message to that form
wm_stylechanged = $007d;
When you call the SetWindowLong function one or more form styles, send this message to the form
Wm_displaychange = $007e;
Send this message to all forms when the resolution of the monitor changes
Wm_geticon = $007f;
This message is sent to a form to return a handle to a large icon or small icon attached to a form;
Wm_seticon = $0080;
The program sends this message to have a new large icon or small icon associated with a form.
Wm_nccreate = $0081;
When a form is first created, this message is sent before the WM_CREATE message is sent.
Wm_ncdestroy = $0082;
This message informs a form that the non-client area is being destroyed
Wm_nccalcsize = $0083;
This message is sent when the customer area of a form must be accounted for
Wm_nchittest = $0084;//Occurs when the mouse is moved, pressed or released
Wm_ncpaint = $0085;
The program sends this message to a form when it (form) 's frame must be drawn;
Wm_ncactivate = $0086;
This message is sent to a form only if its non-client area needs to be changed to show whether it is active or inactive;
Wm_getdlgcode = $0087;
Send this message to a control that is associated with a dialog box program, widdows the control azimuth key and TAB key to make the input enter this control
By responding to Wm_getdlgcode messages. The application can treat him as a special input control and handle it.
Wm_ncmousemove = $00a0;
Send this message to the form//non-client area when the cursor is moved within a form's non-client area: the title bar and window of the form
The Border body
Wm_nclbuttondown = $00a1;
Submit this message when the cursor presses the left mouse button at the same time in a non-client area of a form
Wm_nclbuttonup = $00A2;
When the user releases the left mouse button at the same time, the cursor sends this message to a form in the non-client area 10;
WM_NCLBUTTONDBLCLK = $00A3;
When the user double-clicks the left mouse button the same time the cursor a form in the non-client area 10 sends this message
Wm_ncrbuttondown = $00A4;
This message is sent when the user presses the right mouse button at the same time and the cursor is in the non-client area of the form
Wm_ncrbuttonup = $00A5;
This message is sent when the user releases the right mouse button at the same time while the cursor is in the non-client area of the form
WM_NCRBUTTONDBLCLK = $00A6;
When the user double-clicks the right mouse button at the same time, the cursor sends this message to a form in non-client area 10
Wm_ncmbuttondown = $00a7;
This message is sent when the user presses the middle mouse button at the same time and the cursor is in the non-client area of the form
Wm_ncmbuttonup = $00a8;
This message is sent when the user releases the middle mouse button at the same time and the cursor is in the non-client area of the form
WM_NCMBUTTONDBLCLK = $00a9;
This message is sent when the user double-clicks the middle mouse button at the same time and the cursor is in the non-client area of the form
Wm_keyfirst = $0100;
Wm_keydown = $0100;
Press a key
Wm_keyup = $0101;
Release a key
WM_CHAR = $0102;
Press a key and have issued WM_KEYDOWN, WM_KEYUP message
Wm_deadchar = $0103;
Send this message to the focused form when translating wm_keyup messages with the TranslateMessage function
Wm_syskeydown = $0104;
Submits this message to the focused form when the user holds down the ALT key while pressing another key;
Wm_syskeyup = $0105;
When the user releases a key at the same time, the ALT key is also pressed to submit this message to the focused form
Wm_syschar = $0106;
Submit this message to the focused form when the Wm_syskeydown message is translated by the TranslateMessage function
Wm_sysdeadchar = $0107;
Send this message to the focused form when the Wm_syskeydown message is translated by the TranslateMessage function
Wm_keylast = $0108;
Wm_initdialog = $0110;
Send this message to it before a dialog box is displayed. This message is often used to initialize controls and to run other tasks
Wm_command = $0111;
When a user selects a menu command item or when a control sends a message to its parent form, a shortcut key is translated
Wm_syscommand = $0112;
The form receives this message when the user chooses a command on the form menu or when the user chooses to maximize or minimize
Wm_timer = $0113; A timer event has occurred
Wm_hscroll = $0114;
When a form standard horizontal scroll bar produces a scrolling event, this message is sent to that form and also to the control that owns it
Wm_vscroll = $0115;
When a form standard vertical scroll bar produces a scrolling event when this message is sent to that form, it is also sent to the control that owns it wm_initmenu = $0116;
This message is sent when a menu is about to be activated, it occurs on an item in the user's menu bar, or a menu key is pressed. It agrees that the program changes the menu before it is displayed
Wm_initmenupopup = $0117;
This message is sent when a drop-down menu or submenu is about to be activated, and it agrees that the program will change the menu before it is displayed, without changing all
Wm_menuselect = $011f;
Send this message to all the people of the menu (usually the form) when the user selects a menu item
Wm_menuchar = $0120;
When the menu has been activated the user presses a key (different from the accelerator key). Send this message to all the people on the menu;
Wm_enteridle = $0121;
When a modal dialog box or menu enters the no-load state to send this message to all of its people, a modal dialog box or menu enters the no-load state to wait in the queue without a message after processing one or several previous messages
Wm_menurbuttonup = $0122;
Wm_menudrag = $0123;
Wm_menugetobject = $0124;
Wm_uninitmenupopup = $0125;
Wm_menucommand = $0126;
Wm_changeuistate = $0127;
Wm_updateuistate = $0128;
Wm_queryuistate = $0129;
Wm_ctlcolormsgbox = $0132;
Send this message to the all people form of the message box before Windows draws the message box, and in response to this message, the all-people form can set the text and background color of the message box by using the handle of the given related display device
Wm_ctlcoloredit = $0133;
Sends this message to its parent form when an edit control is about to be drawn. By responding to this message. The all people form can set the text and background color of the edit box by using the handle of the given related display device
Wm_ctlcolorlistbox = $0134;
When a ListBox control is about to be drawn before sending this message to its parent form; by responding to this message, the all-people form can set the text and background color of a list box by using the handle of a given related display device
WM_CTLCOLORBTN = $0135;
Sends this message to its parent form when a button control is about to be drawn, by responding to this message. The all people form can set the text and background color of the button by using the handle of the given related display device
Wm_ctlcolordlg = $0136;
When a dialog box control is about to be drawn, send this message to its parent form, by responding to this message. The all people form can set the text background color of the dialog box by using the handle of the given related display device
Wm_ctlcolorscrollbar= $0137;
Sends this message to its parent form when a scrollbar control is about to be drawn; In response to this message, the all-people form can set the background color of the scroll bar by using the handle of the given related display device
Wm_ctlcolorstatic = $0138;
Sends this message to its parent form when a static control is about to be drawn, by responding to this message. The all people form can set the text and background color of a static control by using the handle of a given related display device
Wm_mousefirst = $0200;
Wm_mousemove = $0200;
Move mouse
Wm_lbuttondown = $0201;
Press the left mouse button
Wm_lbuttonup = $0202;
Release left mouse button
WM_LBUTTONDBLCLK = $0203;
Double click left mouse button
Wm_rbuttondown = $0204;
Press the right mouse button
Wm_rbuttonup = $0205;
Release the right mouse button
WM_RBUTTONDBLCLK = $0206;
Double-click the right mouse button
Wm_mbuttondown = $0207;
Press the middle mouse button
Wm_mbuttonup = $0208;
Release middle mouse button
WM_MBUTTONDBLCLK = $0209;
Double-click the middle mouse button
WM_MouseWheel = $020a;
Sends this message when the mouse wheel is rotated a control that currently has focus
Wm_mouselast = $020a;
Wm_parentnotify = $0210;
When an MDI child form is created or destroyed. Or the user presses the mouse button while the cursor is on the subform and sends this message to its parent form
Wm_entermenuloop = $0211;
Send this message to notify the application of the main form that has entered the menu loop mode
Wm_exitmenuloop = $0212;
Send this message to notify the application of the main form that has exited the menu loop mode
Wm_nextmenu = $0213;
wm_sizing = 532;
This message is sent to the form when the user is resizing the form, and the message application is able to monitor the size and position of the form and change their
wm_capturechanged = 533;
Send this message to the form when it loses the captured mouse.
wm_moving = 534;
When the user sends this message while the form is being moved, the message application is able to monitor the form size and location as well as change them.
Wm_powerbroadcast = 536;
This message is sent to the application to notify it about power management events.
Wm_devicechange = 537;
Send this message to the application or device driver when the device's hardware configuration changes
Wm_ime_startcomposition = $010d;
Wm_ime_endcomposition = $010e;
Wm_ime_composition = $010f;
Wm_ime_keylast = $010f;
Wm_ime_setcontext = $0281;
Wm_ime_notify = $0282;
Wm_ime_control = $0283;
Wm_ime_compositionfull = $0284;
Wm_ime_select = $0285;
Wm_ime_char = $0286;
Wm_ime_request = $0288;
Wm_ime_keydown = $0290;
Wm_ime_keyup = $0291;
Wm_mdicreate = $0220;
The application sends this message to a multi-document customer form to create an MDI child form
Wm_mdidestroy = $0221;
The application sends this message to a multi-document customer form to close an MDI child form
Wm_mdiactivate = $0222;
The application sends this message to a multi-document customer form to notify the customer that the form is active and also has an MDI child form. When the customer form receives this message. It emits a wm_mdiactive message to the MDI child form (not activated) to activate it;
Wm_mdirestore = $0223;
The program sends this message to the MDI client form to restore the subform from the maximum to its original size
Wm_mdinext = $0224;
The program sends this message to the MDI customer form to activate the next or previous form
Wm_mdimaximize = $0225;
The program sends this message to the MDI client form to maximize an MDI child form;
Wm_mditile = $0226;
The program sends this message to the MDI client form to arrange all the MDI child forms again in a tiled fashion
Wm_mdicascade = $0227;
The program sends this message to the MDI customer form to cascade all the MDI child forms again
Wm_mdiiconarrange = $0228;
The program sends this message to the MDI customer form to arrange all of the minimized MDI child forms again
Wm_mdigetactive = $0229;
The program sends this message to the MDI client form to find a handle to the active subform
Wm_mdisetmenu = $0230;
The program sends this message to the MDI customer form to replace the submenu of the subform with an MDI menu
Wm_entersizemove = $0231;
Wm_exitsizemove = $0232;
Wm_dropfiles = $0233;
Wm_mdirefreshmenu = $0234;
Wm_mousehover = $02A1;
Wm_mouseleave = $02a3;
Wm_cut = $0300;
The program sends this message to an edit box or ComboBox to delete the currently selected text
Wm_copy = $0301;
The program sends this message to an edit box or ComboBox to copy the currently selected text to the Clipboard
Wm_paste = $0302;
The program sends this message to the Editcontrol or ComboBox to get data from the Clipboard
Wm_clear = $0303;
The program sends this message to the Editcontrol or ComboBox to clear the currently selected content;
Wm_undo = $0304;
The program sends this message to the Editcontrol or ComboBox to undo the last action
Wm_renderformat = $0305;
Wm_renderallformats = $0306;
Wm_destroyclipboard = $0307;
This message is sent to all of the Clipboard when the Enptyclipboard function is called
Wm_drawclipboard = $0308;
Sends this message to the first form of the Clipboard watch chain when the contents of the Clipboard change; it agrees to use the Clipboard to observe the form to
Displays the new contents of the Clipboard.
Wm_paintclipboard = $0309;
When the clipboard includes data in Cf_ownerdiplay format and the client area of the Clipboard watch form needs to be redrawn;
Wm_vscrollclipboard = $030a;
Wm_sizeclipboard = $030b;
When the clipboard includes data in cf_ownerdiplay format and the size of the customer area of the Clipboard watch form has changed, this message is sent through the Clipboard watch form to all the people on the Clipboard.
Wm_askcbformatname = $030c;
Send this message through the Clipboard watch form to all the Clipboard names to request a Cf_ownerdisplay-formatted clipboard name
Wm_changecbchain = $030d;
When a form is removed from the Clipboard watch chain, this message is sent to the first form of the Clipboard watch chain.
Wm_hscrollclipboard = $030e;
This message is sent to the Clipboard through a Clipboard observation form, which occurs when the Clipboard includes data in cfownerdispaly format and there is an event on the horizontal scroll bar of the Clipboard Watch window; all should scroll the Clipboard image and update the scroll bar value;
Wm_querynewpalette = $030f;
This message is sent to the form that will receive the focus. This message enables the form to have the opportunity to implement his logical palette at the same time when it receives the focus
Wm_paletteischanging= $0310;
When an application is about to implement its logical palette, send this message to notify all applications
wm_palettechanged = $0311;
This message changes the system palette by sending this message to all top-level and overlapping forms after it implements its logical palette in a focused form.
Wm_hotkey = $0312;
This message is submitted when the user presses a hotkey that is registered by the RegisterHotKey function
Wm_print = 791;
The application sends this message only when Windows or another application makes a request to draw part of an application;
Wm_printclient = 792;
Wm_handheldfirst = 856;
Wm_handheldlast = 863;
Wm_penwinfirst = $0380;
Wm_penwinlast = $038f;
Wm_coalesce_first = $0390;
Wm_coalesce_last = $039f;
Wm_dde_first = $03E0;
Wm_dde_initiate = wm_dde_first + 0;
A DDE client submits this message to start a session with the server program in response to the specified program and subject name.
Wm_dde_terminate = Wm_dde_first + 1;
A DDE application (either client or server) submits this message to terminate a session.
Wm_dde_advise = Wm_dde_first + 2;
A DDE client submits this message to a DDE service program to request that the server update it whenever the data item changes
Wm_dde_unadvise = Wm_dde_first + 3;
A DDE client notifies a DDE service through this message that the item is not updated by the specified item or a special Clipboard format
Wm_dde_ack = Wm_dde_first + 4;
This message informs a DDE (Dynamic data exchange) program that it has received and is processing Wm_dde_poke, Wm_dde_execute, Wm_dde_data, Wm_dde_advise, wm_dde_unadvise, or Wm_dde_ Initiat message
Wm_dde_data = Wm_dde_first + 5;
A DDE service program submits this message to a DDE client to pass a data item to the customer or to notify the customer of an available data item
Wm_dde_request = Wm_dde_first + 6;
A DDE client submits this message to a DDE service program to request the value of a data item;
Wm_dde_poke = Wm_dde_first + 7;
A DDE client submits this message to a DDE service program, which the customer uses to request that the server receive an unsolicited data item; The server prompts the message by replying to wm_dde_ack whether it receives the data item.
Wm_dde_execute = Wm_dde_first + 8;
A DDE client submits this message to a DDE service program to send a string to the server so that it is processed like a serial command, and the server responds by submitting a wm_dde_ack message;
Wm_dde_last = Wm_dde_first + 8;
Wm_app = $8000;
Wm_user = $0400;


WPARAM and LPARAM are further specific information, generally including menu item content or mouse click location and other specific information.


Three messages that you typically have to process:
Wm_create the message that was sent when the form was originally created. When this message is generally processed, some settings, initialization, and resource allocation are performed.
WM_PAINT the message is sent when the content of the form needs to be redrawn.

This message is generated when the user moves the form or resizes the form or is obscured by an application pop-up form. WM_PAINT is very important for DirectX games. It doesn't matter, because we redraw the screen at a rate of 30-60fps (frames per second). For ordinary Windows applications, it is important to redraw, or it will be obscured by other forms.

For DirectX applications, we don't want windows to feel that the screen is not redrawn, so let the Windows system know that we've processed the message.
Therefore, the simplest way to validate the customer rectangle for a form is to call BeginPaint () and EndPaint (). These two functions validate the form. Fill the background again with the background brush stored in the Windows class variable Hbrbackground. This is usually the case:

HDC = BeginPaint (hWnd, &ps);//TODO: Add random drawing code here ... EndPaint (HWnd, &ps);


The HWND is the form handle. Two functions draw on the corresponding form. PS is the address of the PAINTSTRUCT structure, which includes the area to redraw.

Its structure is as follows:

typedef struct TAGPAINTSTRUCT {    hdc         hdc;    BOOL        ferase;    RECT        Rcpaint;    BOOL        Frestore;    BOOL        fincupdate;    BYTE        rgbreserved[32];} Paintstruct



The most important field here is Rcpaint, which is a RECT structure. Includes the smallest rectangle that needs to be redrawn. Windows tries to do as little work as possible. When the form is broken. Windows tells you that you need to paint again to restore the smallest rectangular area of the form's content.

BeginPaint () returns a graphics scene handle or a device context handle.


The Wm_destroy form is destroyed when the message is sent.

Typically, the user clicks the close icon of the form or selects the immediate result after closing from the form's system menu. All resources need to be released here. and to tell Windows to completely terminate the process by sending a wm_quit message.


This message here only closes the form, but does not close the application. The application will continue to execute just without the form. So here the message terminating the program is wm_quit. is to send it with a special function postquitmessage () function. Call PostQuitMessage (0) to add the Wm_quit message to the message queue, which causes the main loop event to end.


In the Wm_destroy. Handles all cleanup work, and then calls PostQuitMessage (0) to end the main loop.




After processing the message, use return (0), exit WinProc, and tell Windows that the message has been processed.

For other messages that are processed, call the default message Handler Defaultwindowproc (), which is a pass-through function that will pass the processed message to Windows for default processing.
Return DefWindowProc (hWnd, message, WParam, LParam);

Event handler WinProc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.