Principle of using the API message sending program by shaoyun 2010-03-20
Very simple: the most basic application of several API functions. The code I wrote is also the simplest implementation method. Of course, the higher-order point is implemented through the Hook method.
Principle:
Use the Form class nameFindwindowTo obtain the window handle.FinddomainwexObtain the form handle of the editing box.
WithSendmessageFunction sendingWm_gettextGet the text in the edit box, add your own message, and send it.Wm_settextMessage to set the content of the corresponding child form of the Target Program
Here is an example code. click the button to append a text section to notepad. In practice, you also need to set a timer to cyclically detect the target program to send messages.
Code
1 procedure tform1.btn1click (Sender: tobject );
2 VaR
3 starget, smsg: string;
4 htargetwnd, hedit: thandle;
5 szbuff: array [0 .. 255] of char;
6 begin
7 starget: = 'notepad ';
8 htargetwnd: = findwindow (pwidechar (starget), nil );
9 If htargetwnd <> 0 then
10 begin
11 setforegroundwindow (htargetwnd );
12 hedit: = find1_wex (htargetwnd, 0, pwidechar ('edit'), nil );
13 if hedit <> 0 then
14 begin
15 sendmessage (hedit, wm_gettext, sizeof (szbuff), INTEGER (@ szbuff ));
16 smsg: = szbuff + 'append information! ';
17 sendmessage (hedit, wm_settext, 0, INTEGER (pwidechar (smsg )));
18 end;
19 end;
20 end;
Code test environment: Windows XP SP3 + Delphi 2010