CodePudding user response:
unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1=class (TForm)
For: TButton;
Edit1: TEdit;
Procedure Button1Click (Sender: TObject);
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. Button1Click (Sender: TObject);
Var
H: HWND;
Size: Integer;
CopyDataStruct: TCopyDataStruct;
The begin
H:=FindWindow (nil, 'receiving window). {according to the title search target window}
If h & gt; 0 then
The begin
Size:=ByteLength (Edit1. Text) + 2; {the extra two bytes used in the back of the # 0}
CopyDataStruct. LpData:=PChar (Edit1. Text + # 0); {string to be sent, # 0 said PChar end}
CopyDataStruct. DwData:=WM_COPYDATA; {specified message type}
CopyDataStruct. CbData:=the Size; {specify the size of data to be sent}
SendMessage (h, WM_COPYDATA to 0, the Integer (@ CopyDataStruct)); Send {}
end;
end;
End.
Receive code:
The unit Unit1;
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1=class (TForm)
Memo1: TMemo;
Procedure FormCreate (Sender: TObject);
Private
Protected
Procedure WMCopyData (var Message: TWMCopyData); The message WM_COPYDATA;
Public
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. FormCreate (Sender: TObject);
The begin
Caption:='receiving window;
end;
Procedure TForm1. WMCopyData (var Message: TWMCopyData);
The begin
Memo1. Lines. The Add (PChar (Message. CopyDataStruct. LpData));
end;
End.
CodePudding user response:
If it is the same process, can be overloaded WndProc, if, is another process with hooks (Hook) intercept