begin
CreateMutex(Nil,false,'project1');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
if Application.MessageBox('程序project1正在运行,是否再另外打开一个?','project1',4)=IDNO then
begin
SendMessage(HWND_BROADCAST,RegisterWindowMessage('eExs'),0,0);
Halt(0);
end;
end;
Application.Initialize;
Application.CreateForm(Tfrmmain, frmmain);
Application.Run;
end.
procedure CheckPrevInstance;
var
PrevWindow: HWND;
i: Integer;
Atom: TAtom;
begin
if GlobalFindAtom(PChar('APPLICATION_IS_RUNNING')) = 0 then
begin
CheckPreInsAtom := GlobalAddAtom(PChar('APPLICATION_IS_RUNNING'));
end else
begin
repeat
PrevWindow := FindWindow('MAINFORM_CLASS', nil);
until PrevWindow <> 0;
for i := 1 to ParamCount do
begin
Atom := GlobalAddAtom(PChar(ParamStr(i)));
SendMessage(PrevWindow, WM_XXXX, Atom, 0); // 通知消息
GlobalDeleteAtom(Atom);
end;
SetForeGroundWindow(PrevWindow);
SendMessage(PrevWindow, WM_XXXX, 0, 0); // 通知消息
Halt;
end;
end;