program Project1;<br>uses<br> Forms,<br> Windows,<br> Messages,<br> SysUtils,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.res}<br><br>procedure SendParamMsg(Handle: THandle; Msg:String);<br>var <br> DS: TCopyDataStruct; <br>begin<br> Ds.cbData:=Length(Msg) + 1; <br> GetMem(Ds.lpData, Ds.cbData ); <br> StrCopy(ds.lpData,PChar(Msg)); <br> SendMessage(Handle, WM_COPYDATA, Application.Handle,Cardinal(@ds)); <br> FreeMem(Ds.lpData);<br>end;<br><br>var <br> h: THandle;<br> i: integer;<br>begin<br> Application.Initialize;<br> h:=FindWindow('TForm1', nil);<br> if (h<>0) and (ParamCount > 0) then<br> begin<br> for i:=1 to ParamCount do<br> SendParamMsg(h, ParamStr(i));<br> Halt;<br> end;<br> Application.CreateForm(TForm1, Form1);<br> Application.Run;<br>end.<br><br>---------------<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StrUtils, StdCtrls;<br><br><br>type<br> TForm1 = class(TForm)<br> Memo1: TMemo;<br> private<br> { Private declarations }<br> procedure ParamMessage(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.ParamMessage(var msg:TWMCopyData);<br>var<br> s:String; <br>begin<br> s:=StrPas(msg.CopyDataStruct^.lpData);<br> //在这里处理消息字符<br> Memo1.Lines.Add(s);<br>end;