//代码
procedure SApp(iAtom: string; ActiveForm: String;
InstanceClass1: TComponentClass; var Reference1);
var
MyHwnd: Hwnd;
begin
if GlobalFindAtom(PWideChar(iAtom)) = 0 then
begin
GlobalAddAtom(PWideChar(iAtom));
Application.Initialize;
Application.CreateForm(InstanceClass1, Reference1);
Application.Run;
GlobalDeleteAtom(GlobalFindAtom(PWideChar(iAtom)));
end
else
begin
// MessageBox(0, 'You can not Run a second copy of this App ', ’ ', mb_OK);
MyHwnd := FindWindow(PWideChar(ActiveForm), 0);
ShowWindow(MyHwnd, SW_Show);
SetForegroundWindow(MyHwnd);
end
end;
调用例子
const
iAtom = ‘xxxApp’;//随便取一个
SApp(iAtom, ‘Tfrmxxxx’, Tfrmxxxx, frmxxxx);