聪明人动嘴笨人出手:
发送端:
procedure TForm1.Button1Click(Sender: TObject);
var uimsg:uint;
tmp
dword;
begin
uimsg:=RegisterWindowMessage('testmsg');
caption:=inttostr(uimsg);
new(tmp);
tmp^:=BSM_APPLICATIONS;
if BroadcastSystemMessage(BSF_NOHANG or BSF_POSTMESSAGE,tmp,
uimsg,
0,0)<>-1 then begin
caption:=caption+'ok'
end else
caption:='???'
end;
接受端
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts;
type
TForm1 = class(TForm)
Button1: TButton;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
uimsg:uint;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
uimsg:=RegisterWindowMessage('testmsg');
caption:=inttostr(uimsg);
end;
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if msg.message=uimsg then begin
CaptioN:='Send message ok';
end;
end;
end.