使用copydata消息也可以。 The WM_COPYDATA message is sent when an application passes data to another application. WM_COPYDATA wParam = (WPARAM) (HWND) hwnd; // handle of sending window lParam = (LPARAM) (PCOPYDATASTRUCT) pcds; // pointer to structure with data ParametershwndIdentifies the window passing the data. pcdsPoints to a COPYDATASTRUCT structure that contains the data to be passed. Return ValuesIf the receiving application processes this message, it should return TRUE; otherwise, it should return FALSE. ResAn application must use the SendMessage function to send this message, not the PostMessage function. The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data. While this message is being sent, the referenced data must not be changed by another thread of the sending process. The receiving application should consider the data read-only. The pcds parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by pcds. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; const mymessage=wm_user+100; type messagestruct=record id:longint; str:string; end; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } procedure domessage(var tt);message mymessage; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var g:messagestruct; sss:string; begin sss:='12345'; g.id:=mymessage; g.str:=sss; form1.Dispatch(g)end;procedure TForm1.domessage(var tt); begin showmessage(messagestruct(tt).str); end;end.
The WM_COPYDATA message is sent when an application passes data to another application. WM_COPYDATA
wParam = (WPARAM) (HWND) hwnd; // handle of sending window
lParam = (LPARAM) (PCOPYDATASTRUCT) pcds; // pointer to structure with data
ParametershwndIdentifies the window passing the data. pcdsPoints to a COPYDATASTRUCT structure that contains the data to be passed. Return ValuesIf the receiving application processes this message, it should return TRUE; otherwise, it should return FALSE. ResAn application must use the SendMessage function to send this message, not the PostMessage function.
The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data.
While this message is being sent, the referenced data must not be changed by another thread of the sending process.
The receiving application should consider the data read-only. The pcds parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by pcds. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; const
mymessage=wm_user+100;
type
messagestruct=record
id:longint;
str:string;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure domessage(var tt);message mymessage;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
g:messagestruct;
sss:string;
begin
sss:='12345';
g.id:=mymessage;
g.str:=sss;
form1.Dispatch(g)end;procedure TForm1.domessage(var tt);
begin
showmessage(messagestruct(tt).str);
end;end.