What is the difference between PostMessage and SendMessage? (example of Enumchildwindowsproc)

Source: Internet
Author: User
Tags ord

PostMessage just put the message in the queue, regardless of whether the other program is processing to return, and then continue to execute;
SendMessage must wait for other programs to process the message before returning and continuing.
The return value of PostMessage indicates whether the PostMessage function is executed correctly;
The return value of SendMessage, however, indicates the return value after the message was processed by another program.


Font size: Big middle and small teach you: Delphi Get handle SendMessage
Find the handle to another window: handle: = FindWindow (Nil,pchar (' title of Window) ');//Find form handle
Find Subform: Childhandle: = FindWindowEx (handle,0, ' subform class ', ' subform caption ');
There is also an enumeration subform api,enumchildwindows (the principal body handle, @ CALLBACK function, user parameters);
Use this function to write a callback function, such as:
function Enumchildproc (Ahwnd:hwnd; param:lparam): Boolean; stdcall;
SendMessage (HANDLE,MESSAGE,WL,RL)

Unit Unit1;

Interface

Uses Windows, MESSAGES,TLHELP32, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

Type
TForm1 = Class (Tform)
Procedure Formcreate (Sender:tobject);

Private
{Private declarations}
Public
{Public declarations}
End
var Form1:tform1;
Implementation
{$R *. DFM}

Procedure Tform1.formcreate (sender:tobject);
Var A,b:pansichar;
H:hwnd;
Begin
H:= FindWindow (Nil, ' abc.txt-Notepad ');
h:= FindWindowEx (h,0, ' edit ', nil);
SendMessage (H,wm_settext,255,integer (PChar (' I come to measure ')]);
ShowMessage (IntToStr (h));
End;

SendMessage (Treeview.handle,tvm_setbkcolor,0,rgb (255,0,0)); Set the TV background color
SendMessage (button.handle,wm_lbuttondown,0,0); Left mouse button pressed
SendMessage (button.handle,wm_lbuttonup,0,0); Left mouse button to lift up
SendMessage (Edit.handle,wm_settext,255,integer (PChar (' abc ')); Passing text
SendMessage (Edit.handle,wm_char,wparam (' Q '), 2); Passing characters
SendMessage (button.handle,bm_setstyle,bs_radiobutton,1); Change button style
SendMessage (combobox.handle,cb_setdroppedwidth,300,0); Change Cbdownwidth
Wm_cut, Wm_copy and Wm_paste cut, copy, paste
Implement any key combinations
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
Description: Invokes a window's window function to send a message to that window. Unless the message is processed, the function does not return a SendMessage containing 4 parameters:
1. The HWND 32-bit Window handle window can be any type of screen object because Win32 can maintain handles to most visual objects
2. Wmsg is used to differentiate the constant values of other messages, which can be predefined constants in Windows cells, or they can be custom constants
3. WParam is typically a message-related constant value or a handle to a window or control
4. LParam is typically a pointer to data in memory. Since Wparm, lparam, and pointer are all 32-bit, they can be converted from one to the other
wmsg function
★wm_create Creating a Window
★wm_destroy sent when a window is broken
★wm_move Moving a window
★wm_size changing the size of a window
★wm_activate A window is activated or inactive
★wm_setfocus a window to get focus
★wm_killfocus a window loses focus
★wm_enable A window changes to ENABLE state
★wm_setredraw setting window can redraw
The ★wm_settext application sends this message to set the text of a window
The ★wm_gettext application sends this message to copy the corresponding window's text to the buffer
★wm_gettextlength gets the length of the text associated with a window (does not contain null characters)
★wm_paint asked for a window to repaint himself
★wm_close send a signal when a window or application is about to close
★wm_queryendsession the user selects the End dialog box or the program calls the ExitWindows function itself
★wm_quit used to end program run
★wm_queryopen the user window to restore the previous size position, send this message to an icon
★WM_ERASEBKGND when the window background must be erased (example when the window changes size)
★wm_syscolorchange send this message to all top-level windows when the system color changes
After the message is ★wm_queryendsession, the message is sent to the application informing it that the conversation is over
★wm_showwindow when a hidden or displayed window is sent this message to this window
★wm_activateapp sends this message to the application which window is active and which is inactive
★wm_fontchange send this message to all top-level windows when the system's font repository changes


★wm_timechange send this message to all top-level windows when the system's time changes
★wm_cancelmode send this message to cancel some kind of in-progress (operation)
★wm_setcursor If the mouse causes the cursor to move in a window
★wm_endsession a message is sent to a window when the system process is issued 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 child window when the user clicks on the title bar of this window, or when the window is activated, moves, changes 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 to the window when it is going to change size or position
★wm_painticon sent to the minimized window when its icon is going to be redrawn
★WM_ICONERASEBKGND this message to a minimized window, only if it's background must be redrawn before drawing the icon
★wm_nextdlgct★ send this message to a dialog program to change the focus position
★wm_spoolerstatus this message whenever a print management queue increases or decreases a job
★wm_drawitem sent when the visual appearance of Button,combobox,listbox,menu changes
★wm_measureitem when Button, ComboBox, ListBox, ListView Control, or MenuItem are created
★wm_vkeytoitem This message has a lbs_wantkeyboardinput style issued to its owner in response to the WM_KEYDOWN message
★wm_chartoitem This message is sent by a lbs_wantkeyboardinput-style list box to his owner in response to the WM_CHAR message
★wm_setfont when drawing text The program sends this message to get the color of the control to be used
The ★wm_getfont application sends this message to get the font of the current control drawing text
The ★wm_sethotkey application sends this message to have a window associated with a hotkey
The ★wm_gethotkey application sends this message to determine if a hotkey is associated with a window
★wm_querydragicon This message is sent to the minimized window, when the window is going 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 the icon or the cursor
★wm_compareitem send this message to determine the relative position of the newly added item in the ComboBox or ListBox
★wm_compacting shows little memory.
★wm_windowposchanging Call the SetWindowPos function or other window management function when sending this message to the size and position of the window to be changed
★wm_windowposchanged call SetWindowPos function or other window management function when sending this message to the size and position of the window has been changed
★wm_power This message is sent when the system is about to enter a paused state
★wm_copydata send this message when an application passes data to another application
★wm_canceljourna when a user cancels the program log activation status, submits this message to the program
★wm_notify send this message to its parent window when an event for a control has occurred or if the control needs to get some information
★wm_inputlangchangerequest when the user chooses an input language, or the hotkey of the input language changes
★wm_inputlangchange send this message to the affected top-level window when the platform field has been changed
★wm_tcard send this message to the application when the program has initialized the Windows Help routine
★wm_help This message shows that the user pressed F1, if a menu is active, send this message to the menu associated with this window, otherwise it will be sent to the focus window, if there is currently no focus, send this message to the currently activated window
★wm_userchanged when a user has logged in or exited to send this message to all Windows, the system updates the user's specific settings when the user log in or exits, and the system sends this message as soon as the user updates the settings
★wm_notifyformat common controls, custom controls, and their parent window use this message to determine whether a control is using an 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

Http://www.cnblogs.com/snow001x/archive/2008/11/15/1334160.html

What is the difference between PostMessage and SendMessage? (example of Enumchildwindowsproc)

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.