送端<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Edit1: TEdit;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> H: THandle;<br> CopyDataStruct: TCopyDataStruct;<br>begin<br> h:=FindWindow(nil, 'App1');<br> if h&lt;&gt;0 then<br> begin<br> CopyDataStruct.cbData:=Length(Edit1.Text)+1;<br> CopyDataStruct.lpData:=PChar(Edit1.Text);<br> SendMessage(h, WM_CopyData, 0, LParam(@CopyDataSTruct))<br> end<br>end;<br><br>end.<br>接受端:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs;<br><br>type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> procedure WMCopyData(var Msg: TWMCopyData); message WM_CopyData;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> Caption:='App1'<br>end;<br><br>procedure TForm1.WMCopyData(var Msg: TWMCopyData);<br>var<br> s: string;<br>begin<br> s:=StrPas(PChar(Msg.CopyDataStruct^.lpData));<br> ShowMessage(s)<br>end;<br><br>end.