Mainly use sendmessage () function;
About sendmessage
Compile: snowapex
This article is a summary of sendmessage translation in msdn.
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.
. 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 are processed only when the receiving thread executes the message retrieval 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)
Above begin from http://www.vckbase.com/document/viewdoc? Id = 1731, VC knowledge.
The following figure shows the generation of the parameter indicator:
_ Fastcall tform1: tform1 (tcomponent * owner)
: Tform (owner)
{
Sendmessagea (this-> handle, wm_syscommand, SC _monitorpower, 2); // indicates whether the listener is enabled.
Sleep (10000)
Sendmessagea (this-> handle, wm_syscommand, SC _monitorpower,-1); // open the timer
}