在主窗体的Create事件中写入:
procedure TFAppServer.FormCreate(Sender: TObject);
var
ZAppName: array[0..127] of char;
Hold: String;
Found: HWND;
begin
Hold := Application.Title;
Application.Title := 'OnlyOne'+ IntToStr(HInstance);
StrPCopy(ZAppName, Hold);
Found := FindWindow(nil, ZAppName);
Application.Title := Hold;
if Found<>0 then
begin
ShowWindow(Found, SW_RESTORE);
Application.Terminate;
end;
registerhotkey(FAppServer.handle,1,mod_alt,vk_return);
FAppServer.windowstate := wsminimized;
Application.OnMinimize:=appMINIMIZE;
end;
调用的函数为
procedure TFAppServer.appMINIMIZE(Sender: TObject);
begin
ShowWindow(FAppServer.Handle,SW_HIDE);
ShowWindow(Application.Handle,SW_HIDE);
end;