unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, sockets; const wm_mymessage = wm_user + 1; type TForm1 = class(TForm) btn1: TButton; procedure FormShow(Sender: TObject); procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure mymessage(var Msg: TMsg; var Handled: Boolean); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin application.onmessage := mymessage; end; procedure TForm1.mymessage(var Msg: TMsg; var Handled: Boolean); begin if msg.message = wm_mymessage then showmessage( 'ok '); end; procedure TForm1.btn1Click(Sender: TObject); begin // sendmessage(handle, wm_mymessage,0, 0); // sendmessage(application.handle, wm_mymessage,0, 0); // postmessage(application.handle, wm_mymessage,0, 0); // end;