//分少了点,但总比没有好<br>//接受<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br>Const<br>SfMsg : Array[0..2] of String=('股东信息','代理一信息','代理二信息');<br>Type<br> SFArray= Array[1..20]of Char ;<br><br>type<br> TForm1 = class(TForm)<br> Memo1: TMemo;<br> private<br> { Private declarations }<br> procedure Receivemsg(var Message: TMessage) ; Message WM_COPYDATA;<br> public<br> { Public declarations }<br> end;<br>PSfyzxtInformation = ^TSfyzxtInformation;<br>TSfyzxtInformation = packed record<br> Checkid: SFArray ;<br> Name: SFArray ;<br> CardId: SFArray ; <br> end;<br><br>var<br> Form1: TForm1;<br> Inf: PSfyzxtInformation;<br>implementation<br><br>{$R *.DFM}<br><br><br>procedure TForm1.Receivemsg(var Message: TMessage) ;<br>begin<br> Memo1.Lines.Clear ;<br> Memo1.Lines.add(SfMsg[integer(PCOPYDATASTRUCT(Message.LParam)^.dwData) ]);<br> Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Checkid);<br> Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Name);<br> Memo1.Lines.add(PSfyzxtInformation((PCOPYDATASTRUCT(Message.LParam)^.lpData ))^.Cardid);<br>end;<br><br>end.<br><br>//发送<br><br>unit Unit2;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br>Type<br> SFArray= Array[1..20]of Char ;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Label1: TLabel;<br> Edit1: TEdit;<br> Label2: TLabel;<br> Edit2: TEdit;<br> Label3: TLabel;<br> Edit3: TEdit;<br> ComboBox1: TComboBox;<br> Label4: TLabel;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br><br> public<br> { Public declarations }<br> end;<br><br>PSfyzxtInformation = ^TSfyzxtInformation;<br>TSfyzxtInformation = packed record<br> Checkid: SFArray ;<br> Name: SFArray ;<br> CardId: SFArray ; <br> end;<br><br><br>var<br> Form1: TForm1;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>Var<br>Cd : PCOPYDATASTRUCT ;<br>Inf: PSfyzxtInformation;<br>Hwnd:Thandle;<br>begin<br>hwnd:=Findwindow(Nil,'WM_COPYDATA范例');<br>if Hwnd = 0 then begin Showmessage('窗口没有找到!');Exit;end;<br>try<br> Getmem(Inf, sizeof(TSfyzxtInformation));<br> strpcopy(@inf.Checkid,Edit1.Text );<br> strpcopy(@inf.Name,Edit2.Text );<br> strpcopy(@inf.CardId,Edit3.Text );<br> Getmem(cd,sizeof(TCOPYDATASTRUCT));<br> cd.dwData:=Dword(Combobox1.ItemIndex );<br> cd.cbData:=sizeof(SFArray)*3;<br> cd.lpData:=Inf;<br> Sendmessage(Hwnd,WM_COPYDATA,Handle,LPARAM(cd));<br>finally<br> Freemem(cd);<br> Freemem(Inf) ;<br><br>end;<br>end;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> ComboBox1.ItemIndex:= 0 ;<br>end;<br><br>end.<br><br><br>