- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ComCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Edit1: TEdit;
- Edit2: TEdit;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- procedure MyCopyDataMsg(Var Msg : TMessage); Message WM_COPYDATA;
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- var
- cdds : TCopyDataStruct;
- begin
- cdds.dwData := 0;
- cdds.cbData := length(Edit1.Text)+1;
- cdds.lpData := pchar(Edit1.Text);
- SendMessage(Handle,WM_COPYDATA,0,LongWord(@cdds));
- end;
- procedure TForm1.MyCopyDataMsg(var Msg: TMessage);
- var
- cdds : TcopyDataStruct;
- begin
- if msg.Msg = WM_COPYDATA then
- begin
- cdds := PcopyDataStruct(Msg.LParam)^;
- edit2.Text := (Pchar(cdds.lpData));
- end;
- end;
- end.
http://blog.csdn.net/huang_xw/article/details/8015286