Sendmessage function full user manual
First, let's take a look at the message mechanism of windows. Windows is a message-driven system. Program Communication between applications and Windows systems.
For example, open the Notepad program, which has a "file" menu. When running the program, if you click the "new" command in the "file menu", this action will be captured by windows, after analysis on windows, we learned that this action should be handled by the Notepad program we opened, and then windows will send a message, such as the wm_command message that we sometimes use during programming, to notepad, then, notepad will process the message. This process is message processing.
Next, let's talk about sendmessage in the complete form.
Declare function sendmessage lib "USER32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
Alias
Sendmessagea
Description
Call the window function of a window and send a message to that window. This function will not return unless the message is processed.
Sendmessage contains four parameters.
Hwnd 32-bit window handle window can be any type of screen object, because Win32 can maintain the handle of most visual objects
Wmsg is used to distinguish the constant values of other messages. These constants can be pre-defined constants in Windows units, or custom constants. wparam is usually a message-related constant value, it may also be the handle of a window or control.
Lparam is usually a pointer to data in the memory. Since wparm, lparam, and pointer are both 32-bit, they can be converted to each other.
Wmsg Function
Wm_create create a window
Wm_destroy is sent when a window is damaged
Wm_move move a window
Wm_size changes the size of a window.
Wm_activate a window is activated or inactive
Wm_setfocus: one window obtains the focus
Wm_killfocus: A window loses focus.
Wm_enable a window changes to enable status
Wm_setredraw: Specifies whether the window can be repainted.
The wm_settext application sends this message to set the text of a window.
The wm_gettext application sends this message to copy the text of the corresponding window to the buffer zone.
Wm_gettextlength: Get the length of the text related to a window (excluding empty characters)
Wm_paint requires a window to redraw itself
Wm_close send a signal when a window or application is closed
Wm_queryendsession: when the user selects the end dialog box or the program calls the exitwindows Function
Wm_quit is used to end the program running
Wm_queryopen send this message to an icon when the user window recovers the previous size position
Wm_erasebkgnd: when the window background must be erased (for example, when the window size changes)
Wm_syscolorchange send this message to all top-level windows when the system color changes
Wm_endsession when the system process sends the wm_queryendsession message, the message is sent to the application to notify it of the end of the conversation.
Wm_showwindow: When a hidden or displayed window is used, this message is sent to this window.
Wm_activateapp sends this message to the application, which window is activated and which is not activated.
Wm_fontchange send this message to all top-level windows when the system's Font Resource Library changes
Wm_timechange send this message to all top-level windows when the system time changes
Wm_cancelmode sends this message to cancel an ongoing touch (Operation)
Wm_setcursor if the mouse causes the cursor to move in a window and the mouse input is not captured, a message is sent to a window.
Wm_mouseactivate when the cursor is in an inactive window and the user is pressing a key of the mouse to send this message to the current window
Wm_childactivate sends this message to the MDI subwindow. When the user clicks the title bar of this window, or when the window is activated, move and change the size
Wm_queuesync this message is sent by a computer-based training program, and the user input message is separated by the wh_journalpalyback hook program.
Wm_getminmaxinfo this message is sent to the window when it is about to change the size or position
Wm_painticon is sent to the minimization window when its icon is to be repainted
Wm_iconerasebkgnd this message is sent to a minimal window, and its background must be repainted only when it is before the icon is painted.
Wm_nextdlgctl sends this message to a dialog box program to change the focus position
Wm_spoolerstatus this message is sent whenever a job is added or removed in the print management queue.
Wm_drawitem is sent when the visual appearance of Button, ComboBox, ListBox, and menu changes
Wm_measureitem when button, combo box, list box, List View control, or menu item is created
Wm_vkeytoitem this message has an lbs_wantkeyboardinput style sent to its owner to respond to the wm_keydown message
Wm_chartoitem the message is sent to the owner by a list box in the lbs_wantkeyboardinput style to respond to the wm_char message.
Wm_setfont when drawing text, the program sends this message to obtain the color used by the Control
The wm_getfont application sends this message to obtain the font of the text drawn by the current control.
The wm_sethotkey application sends this message to connect a window to a hotkey.
The wm_gethotkey application sends this message to determine whether the hotkey is associated with a window.
Wm_querydragicon the message is sent to the minimization window. When the window is to be dragged and its class does not have a defined icon, the application can return an icon or a cursor handle.
This icon or cursor is displayed when you drag and drop an icon.
Wm_compareitem sends this message to determine
Determine the relative position of the newly added items in ComboBox or ListBox
Wm_compacting shows that the memory is very small
When wm_windowposchanging sends this message to the window whose size and position will be changed, it calls the setwindowpos function or other window management functions.
When wm_windowposchanged sends this message to the window whose size and position have been changed, it calls the setwindowpos function or other window management functions.
Wm_power sends this message when the system is about to pause
Message
Wm_copydata: This message is sent when an application transmits data to another application.
Wm_canceljourna when a user cancels the activation status of the program log, submit the message to the program
Wm_notify when an event of a control has occurred or
When this control needs to obtain some information, it sends this message to its parent window.
Wm_inputlangchangerequest
Wm_inputlangchange send this message to the affected top-level window when the platform site has been changed
Wm_tcard when the program has initialized the Windows Help example
Send this message to the application
Wm_help: the message indicates that the user presses F1.
When a menu is activated, the message is sent to the associated menu of the window. Otherwise, the message is sent to the window with focus. If no focus exists, send the message to the currently activated window.
Wm_userchanged: when the user has logged on or exited, this message is sent to all windows. When the user logs on or exits, the system updates the user's specific settings. When the user updates the settings, the system immediately sends this message.
Wm_policyformat public control. The custom control and its parent window use this message to determine whether the control uses the ANSI or Unicode structure.
Wm_contextmenu: Right-click a user in a window and send the message to this window.
Wm_stylechanging send this message to the window when the setwindowlong function is called to change the style of one or more windows
Wm_stylechanged: When the setwindowlong function is called for one or more windows, this message is sent to that window.
Wm_displaychange send this message to all windows after the display resolution changes
Wm_geticon the message is sent to a window to return
Window-related large icon or small icon handle
Wm_seticon program sends this message to make a new big icon
Or associate a small icon with a window.
Wm_nccreate when a window is created for the first timeThe message is sent before the wm_create message is sent.
Wm_ncdestroy this message notifies a window, not the customer area
Destroying
Wm_nccalcsize when the customer area of a window must be checked
Send this message during Calculation
Wm_nchittest move the mouse and press or release the mouse
Raw
The wm_ncpaint program sends this message to a window when it
(Window) frame must be drawn
Wm_ncactivate this message is sent to a window only when its
Non-customer zones need to be changed to show whether they are activated or not.
Wm_getdlgcode sends this message to a dialog box Program
The left-side Navigation Pane and the left-side navigation pane of the left-side Navigation Pane.
Wm_ncmousemove send this message when the cursor moves in a non-customer area of a window to the non-customer area of the window: The title bar of the form and the border body of the window
Wm_nclbuttondown: this message is submitted when the cursor is in the non-customer area of a window and the left mouse button is pressed at the same time.
Wm_nclbuttonup
Wm_nclbuttondblclk: When you double-click the left mouse button and a window with the cursor sends this message in non-customer Zone 10
Wm_ncrbuttondown: This message is sent when you right-click the user and the cursor is in a non-customer area of the window.
Wm_ncrbuttonup: This message is sent when the user releases the right mouse and the cursor is in a non-customer area of the window.
Wm_ncrbuttondblclk when the user double-click the right mouse and the cursor in a window in non-customer Zone 10 to send this message
Wm_ncmbuttondown: This message is sent when you press the middle mouse button and the cursor is in a non-customer area of the window.
Wm_ncmbuttonup: This message is sent when the user releases the middle mouse button and the cursor is in a non-customer area of the window.
Wm_ncmbuttondblclk: This message is sent when you double-click the key and move the cursor to a non-customer area in the window.
Wm_keyfirst wm_keydown press the next key
Wm_keyup releases a key
Wm_char: press a key and the wm_keydown and wm_keyup messages have been sent.
Use the translatemessage function to translate wm_deadchar
When a wm_keyup message is sent, the message is sent to a window with focus
Wm_syskeydown when the user presses the Alt key and other
When the key is used, submit the message to the window with focus
Wm_syskeyup
The message is also submitted to the window with focus when it is pressed.
Wm_syschar when wm_syskeydown message
After being translated by the translatemessage function, submit this message to the window with focus
Wm_sysdeadchar when wm_syskeydown message
This message is sent to the window with focus after being translated by the translatemessage function.
Wm_initdialog is sent before a dialog box program is displayed.
Send this message to it. This message is usually used to initialize the control and execute other tasks.
Wm_command when you select a menu command item or when a control sends a message to its parent window, a shortcut key is translated
Wm_syscommand
To or when the user chooses to maximize or minimize the number of messages received in that window
A timer event occurs in wm_timer.
Wm_hscroll: when a standard horizontal scroll bar of a window generates a rolling event, this message is sent to that window and the control that owns it.
Wm_vscroll: when a standard vertical scroll bar of a window generates a rolling event, this message is sent to that window and the control that owns it.
Wm_initmenu sends this message when a menu is to be activated. It occurs in a menu bar of the user or presses a menu key, which allows the program to change the menu before display.
Wm_initmenupopup send this message when a drop-down menu or sub-menu is to be activated. It allows the program to change the menu before it is displayed, instead of changing all
Wm_menuselect is sent when a menu item is selected
This message is sent to the menu owner (usually a window)
Wm_menuchar when the menu has been activated and the user presses a key (different from the acceleration Key), this message is sent to the menu owner
Wm_enteridle sends this message to its owner when a modal dialog box or menu enters the no-load status, when a modal dialog box or menu enters the no-load status, it waits for no messages in the queue after processing one or more previous messages.
Wm_ctlcolormsgbox sends the message to the owner window of the message box before drawing the message box in windows, in the owner window, you can set the text and background color of the message box by using the given handle of the display device.
Wm_ctlcoloredit: When an editing control is to be drawn
When this message is sent to its parent window, the owner window can set the text and background color of the edit box by using the handle of the given display device.
Wm_ctlcolorlistbox when a list box control is to be drawn, send this message to its parent window in response to this message, in the owner window, you can set the text and background colors of the list box by using the given handle of the display device.
Wm_ctlcolorbtn when a button control is to be drawn
The parent window that sends this message responds to this message. The owner window can set the text and background color of the button by using the handle of the specified display device.
Wm_ctlcolordlg when a dialog box control is to be drawn
Send this message to its parent window. In response to this message, the owner window can set the text background color of the dialog box by using the handle of the given display device.
Wm_ctlcolorscrollbar send this message when a scroll bar control is to be drawn to its parent window to respond to this message. The owner window can set the background color of the scroll bar by using the handle of the given display device.
Wm_ctlcolorstatic: When a static control is to be drawn, this message is sent to its parent window to respond to this message, in the owner window, you can set the text and background color of the static control by using the given handle of the display device.
Wm_mousefirst wm_mousemove move the mouse
Wm_lbuttondown
Wm_lbuttonup
Wm_lbuttondblclk double-click the left mouse button
Wm_rbuttondown right-click
Wm_rbuttonup right-click to release
Wm_rbuttondblclk, right-click
Wm_mbuttondown
Wm_mbuttonup
Wm_mbuttondblclk double-click
Wm_mousewheel: A control with focus is sent when the mouse wheel is turned.
Wm_parentnotify when the MDI child window is created or destroyed
Or the user presses the mouse key and the cursor sends the message to its parent window when the child window is located.
Wm_entermenuloop sends this message to notify the application
Main Window that has entered the menu loop mode
Wm_exitmenuloop sends this message to the application
Main Window that has exited the menu loop mode
Wm_sizing: when the user is adjusting the window size, the user can send this message to the window. Through this message application, the user can monitor the window size and position and modify them.
Wm_capturechanged send this message to the window when it is missing
When capturing the mouse
Wm_moving: This message is sent when the user moves the window. With this message application, the user can monitor the window size and position and modify them.
Wm_powerbroadcast this message is sent to the application
Know about its power management events Wm_devicechange when the hardware configuration of the device changes Send this message to the application or device driver The wm_mdidestroy application sends this message to multiple files. To close an MDI child window. The wm_mdiactivate application sends this message to multiple files. Notify the customer window of the customer window to activate another MDI subwindow. When the customer window receives the message, it sends the wm_mdiactive message to the MDI subwindow (not activated) to activate it. The wm_mdirestore program sends this message to the MDI customer. The window allows the sub-window to be restored from the maximum to the original size. The wm_mdinext program sends this message to the MDI client. Activate the next or previous window The wm_mdimaximize program sends this message to the MDI client. Window to maximize an MDI subwindow The wm_mditile program sends this message to the MDI client. Rearrange all MDI child windows in Tiled Mode The wm_mdicascade program sends this message to the MDI client. Window re-arrange all MDI child windows in cascade Mode The wm_mdiiconarrange program sends this message to the MDI customer window to rearrange all the minimized MDI child windows. The wm_mdigetactive program sends this message to the MDI client. Window to find the handle of the activated sub-Window The wm_mdisetmenu program sends this message to the MDI client. Replace the Child Window Menu With the MDI menu The wm_cut program sends this message to an edit box or ComboBox to delete the selected text. The wm_copy program sends this message to an edit box or ComboBox to copy the selected text to the clipboard. The wm_paste program sends this message Obtain data from the clipboard for editcontrol or ComboBox. The wm_clear program sends this message Clears the selected content for editcontrol or ComboBox. The wm_undo program sends this message to editcontrol or ComboBox to cancel the last operation. Wm_destroyclipboard send this message to the clipboard owner when the enptyclipboard function is called. Wm_drawclipboard when the content of the clipboard changes Send this message to the first window of the clipboard observation chain. It allows the clipboard observation window to display new content of the clipboard. Wm_paintclipboard when the Clipboard contains data in the cf_ownerdiplay format and the client area of the clipboard observation window needs to be repainted Wm_sizeclipboard when the Clipboard contains data in the cf_ownerdiplay format and the size of the client area in the clipboard observation window has changed This message is sent to the clipboard owner through the clipboard observation window. Wm_askcbformatname is sent through the clipboard observation window This message is sent to the clipboard owner to request the name of the clipboard in cf_ownerdisplay format. Wm_changecbchain when a window is observed from the clipboard Send this message to the first window of the clipboard observation chain when the chain is moved in. Wm_hscrollclipboard the message is sent to the clipboard owner through a clipboard observation window. It occurs when the Clipboard contains data in the cfownerdispaly format and an event occurs on the horizontal scroll bar of the clipboard observation window. The owner should scroll the clipboard image and update the value of the scroll bar Wm_querynewpalette this message is sent to the address to be received Vertex window, which enables the window to implement its logical palette when receiving the focus. Wm_paletteischanging this message notifies all applications when an application is about to implement its logical palette Wm_palettechanged The window implements its logical palette and sends this message to all top-level and overlapping windows to change the system palette. Wm_hotkey: this message is submitted when you press the hotkey registered by the registerhotkey function. The wm_print application sends this message only when Windows or other applications send a request to draw part of an application //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /// Sendmessage Function Description: sends a specified message to one or more windows. This function is used to call the window process specified by the window. It is not returned until the Window Process completes message processing. High quality programming
. Function prototype: Lresult sendmessage ( Hwnd, // target window handle Uint MSG, // message to be sent Wparam, // The first message Parameter Lparam // The second Message Parameter ); . Parameters: Hwnd Window handle for receiving messages during the window process. If this parameter is hwnd_broadcast, the message is sent to all top-level windows of the system, including invalid or invisible non-self-owned windows, overwritten windows, and pop-up windows. Messages are not sent to subwindows. MSG Specifies the message to be sent; Wparam Specify the specific information of the additional message; Lparam Specify the specific information of the additional message. . Return Value: The Return Value Returns the message processing result, which depends on the sent message. . Note: Applications that need to communicate in hwnd_broadcast mode should use the registerwindowmessage function to obtain unique messages for inter-Application Communication. If the specified window is created through the call thread, the window process is called immediately as a subroutine. If the specified window is created by calling different threads, the system switches to this thread and calls the appropriate window process. Messages between threads can only be retrieved by the receiving thread.Code. The sending thread will be blocked until the receiving thread finishes processing the message. Windows CE: Windows CE does not support all messages supported by Windows desktop. Before using the sendmessage function, check whether the sent message is supported by Windows CE. . Environment: Windows NT: 3.1 or later; Windows: 95 or later; Windows CE: 1.0 or later; Header file: winuser. h; Input Library: user32.lib; UNICODE: Unicode and ANSI are implemented in windows. . Sample Code: Case wm_keydown: Switch (wparam) {Case vk_home: sendmessage (hwnd, wm_vscroll, sb_top, 0); break; Case vk_end: sendmessage (hwnd, wm_vscroll, sb_bottom, 0); break; case vk_prior: sendmessage (hwnd, wm_vscroll, sb_pageup, 0); break ;...} return 0 ;...
. FAQs 1) Use sendmessage to cut, copy, and paste messages. Sendmessage (hwnd, wm_copy, 0, 0); sendmessage (hwnd, wm_cut, 0, 0); sendmessage (hwnd, wm_paste, 0, 0 ); 2) differences between sendmessage and postmessage Postmessage puts the message into the message queue and returns immediately. sendmessage is not returned until the message is processed in the window. 3) sendmessage send wm_copydata messages to transmit data between processes A wm_copydata message is designed to allow a small amount of read-only data to be transmitted between processes. We recommend that you use the sendmessage () function in the SDK documentation. The receiver does not return data before the data is copied, so that the sender cannot delete or modify data. For example: STD: String strdata = "VC Knowledge Base vckbase. com "; copydatastruct CDs; CDs. dwdata = 0; CDs. cbdata = strdata. length (); CDs. lpdata = strdata. c_str ();: sendmessage (hwnd, wm_copydata, null, (lparam) & CDs );
(Full text) |