// Project1.dpr //
program Project1;
uses
Forms,
messages,
windows,
Unit1 in 'Unit1.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.
// Unit1.pas //
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
WM_BARICON=WM_USER+200;
CM_RESTORE = WM_USER + $1000;
MYAPPNAME = 'My Delphi Program';
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams);
override;
Procedure RestoreRequest(var message: TMessage);
message CM_RESTORE;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.WinClassName := 'My Delphi Program';
end;
procedure TForm1.RestoreRequest(var message: TMessage);
begin
if IsIconic(Application.Handle) = TRUE then
Application.Restore
else
Application.BringToFront;
//showmessage('have run');
end;
end.