program Project1;
uses
Windows,
Messages,
Forms,
Dialogs,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
var
h,h2:Hwnd;
begin
H := FindWindow('TForm1', nil);
if H = 0 then
begin
ShowMessage('没有发现相同的应用程序实例。');
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
begin
ShowMessage('应用程序已经加载');
H2 := FindWindow(nil,'Project1'); //注意恢复application
ShowWindow(h2,SW_MAXIMIZE);
ShowWindow(h,SW_RESTORE);
SetForegroundWindow(H);
Halt;
end;
end.