如果你非要用PostMessage,如下:
方法一:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
Const
CM_ParaMESSAGE = WM_USER + $1001;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure RestoreRequest(var cmessage: TMessage);
message CM_ParaMESSAGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.RestoreRequest(var cmessage: TMessage);
begin
cmessage.Result := 1;
ShowMessage('hello');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle, CM_ParaMESSAGE, 0, 0);
end;
end.
===============================================================================
方法2:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var Mess: TMessage);
override;
end;
var
Form1: TForm1;
MyMsg: UINT;
implementation
{$R *.DFM}
procedure TForm1.WndProc(var Mess: TMessage);
begin
if mess.Msg = MyMsg then
begin
ShowMessage('hello');
end;
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyMsg := RegisterWindowMessage('WM_ZW_TEST');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle,MyMsg,0,0);
end;
end.