Delphi gets the handle and sends the message!

Source: Internet
Author: User

Delphi obtains the handle and sends the message

Find the handle of another window: handle: = findwindow (nil, pchar ('window title'); // check the form handle
Find the child form: childhandle: = find=wex (handle, 0, 'Child form class', 'Child form title ');
In addition, there is an API for enumerating sub-forms, enumchildwindows (master account handle, @ callback function, user parameter );
To use this function, you need to write a callback function, for example:
Function enumchildproc (ahwnd: hwnd; Param: lparam): Boolean; stdcall;
Sendmessage (handle, message, wl, rl)

 

 

Unit unit1; </P> <p> interface </P> <p> uses Windows, messages, tlhelp32, sysutils, classes, graphics, controls, forms, dialogs, stdctrls; </P> <p> type <br/> tform1 = Class (tform) <br/> procedure formcreate (Sender: tobject ); </P> <p> private <br/> {private Declarations} <br/> Public <br/> {public declarations} <br/> end; <br/> var form1: tform1; <br/> Implementation <br/> {$ R *. DFM} </P> <p> procedure tform1.formcreate (Sender: tobject); <br/> var A, B: pansichar; <br/> H: hwnd; <br/> begin <br/> H: = findwindow(nil,'abc.txt-Notepad '); <br/> H: = find1_wex (H, 0, 'edit', nil ); <br/> sendmessage (H, wm_settext, 255, INTEGER (pchar ('I have measured'); <br/> showmessage (inttostr (h )); <br/> end; <br/>

 

 

Sendmessage (Treeview. Handle, tvm_setbkcolor, 0, RGB (, 0); set the TV background color
Sendmessage (button. Handle, wm_lbuttondown,); left click to press
Sendmessage (button. Handle, wm_lbuttonup,); left mouse button lifted
Sendmessage (edit. Handle, wm_settext, 255, INTEGER (pchar ('abc'); pass text
Sendmessage (edit. Handle, wm_char, wparam ('q'), 2); pass character
Sendmessage (button. Handle, bm_setstyle, bs_radiobutton, 1); change the button style
Sendmessage (ComboBox. Handle, cb_setdroppedwidth, 0); change cbdownwidth
Wm_cut, wm_copy, and wm_paste cut, copy, and paste
Any combination of keys
Keybd_event (vk_control, mapvirtualkey (vk_control, 0), 0, 0 );
Keybd_event (ord ('V'), mapvirtualkey (ord ('V'), 0), 0, 0 );
Keybd_event (ord ('V'), mapvirtualkey (ord ('V'), 0), keyeventf_keyup, 0 );
Keybd_event (vk_control, mapvirtualkey (vk_control, 0), keyeventf_keyup, 0 );

Sendmessagea
Note: Call the window function of a window to send a message to that window. Unless the message processing is complete, this function does not return the sendmessage containing four parameters:
1. The hwnd 32-bit window handle window can be any type of screen object, because Win32 can maintain the handle of most visual objects.
2. wmsg is used to distinguish the constant values of other messages. These constants can be pre-defined constants in Windows units or custom constants.
3. wparam is usually a message-related constant value, or a handle to a window or control.
4. 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: select the end dialog box or the program calls the exitwindows function.
★Wm_quit is used to end the program running
★When the wm_queryopen user window restores the previous size position, send this message to an icon
★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
★After the wm_queryendsession message is sent, the message is sent to the application to notify it whether the conversation has ended.
★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
★Wm_endsession sends a message to a window when the system process sends out and the mouse input is not captured
★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 the window is activated, moved, and changed
★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_nextdlgct★Send 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, ComboBox, ListBox, listview control, or menuitem 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 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
★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 the control needs to obtain some information, send 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 send this message to the application when the program has initialized the Windows Help routine
★Wm_help indicates that the user presses F1. If a menu is activated, the user sends the message to the menu associated with this window; otherwise, the message is sent to the window with focus, if no focus exists, send the message to the active 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.

Function enumchildwindowsproc (hwnd, lparam: integer): Boolean;
VaR
Buffer: array [0 .. 255] of char;
Begin
Result: = true;
Getclassname (hwnd, buffer, 256 );
If strpas (buffer) = 'edit' then
Begin
Sendmessage (hwnd, wm_gettext, 256, lparam );
Result: = false;
End;
End;

Procedure tform1.button1click (Sender: tobject );
VaR
Hwnd: integer;
Buffer: array [0 .. 255] of char;
Begin
Hwnd: = findwindow ('cabinetwclass', nil );
If hwnd <> 0 then
Begin
Enumchildwindows (hwnd, @ enumchildwindowsproc, longint (@ buffer [0]);
Caption: = strpas (buffer );
End;
End;

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.