program test;
uses
Forms,
windows,
messages,
Main in 'Main.pas' {Form1};
const
CM_RESTORE = WM_USER + $1000;
{自定义的“恢复”消息}
MYAPPNAME = 'My Delphi Program';
var
RvHandle : hWnd;
{$R *.RES}
begin
RvHandle := FindWindow(MYAPPNAME,NIL);
if RvHandle > 0 then
begin
PostMessage(RvHandle,CM_RESTORE,0,0);
Exit;
end;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
////////////////////////
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
const
CM_RESTORE = WM_USER + $1000;
{自定义的“恢复”消息}
MYAPPNAME ='My Delphi Program';
type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
procedure CreateParams(var Params: TCreateParams);
override;
Procedure RestoreRequest(var message: TMessage);
message CM_RESTORE;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WinClassName := MYAPPNAME;
end;
{处理“恢复”消息}
procedure TForm1.RestoreRequest(var message: TMessage);
begin
if IsIconic(Application.Handle) = TRUE then
Application.Restore
else
Application.BringToFront;
end;
end.