I found this code works, and is really easy to implement...
In the Application source...
var
hMutex: THandle ;
begin
hMutex := CreateMutex(nil, False, 'OneCopyMutex') ;
if WaitForSingleObject(hMutex, 0) <> Wait_TimeOut then
begin
Application.Initialize;
...
Application.Run;
end;
end.
Cheers,
Dave.
-----Original Message-----
From: Maurice Butler [mailto:[EMAIL PROTECTED]]
Sent: Friday, 5 February 1999 09:52
To: Multiple recipients of list delphi
Subject: Re: [DUG]: JustOne32
I use the following snip of code in the project.dpf at startup to detect
multiple instances. I isn't super smart but it works and is simple -
what
more could you ask for other than to rap it into a function like
JustOne32.
Maurice Butler
Like Magic Ltd
var
hwndPrev:hwnd;
begin
Application.Initialize;
Application.Title := 'Jetline 2000';
//ensure single instance application
hwndPrev := FindWindow('TfrmStatus','Jetline 2000 Status');
if ( hwndPrev <> 0)
//found previous instance
and (FindWindow('TPropertyInspector','Object Inspector') = 0) then
//not
in delphi
begin
ShowWindow(hwndPrev,SW_RESTORE);
SetForegroundWindow(hwndPrev);
Application.Terminate;
end
else
begin
Application.CreateForm(TdmExceptionTrap, dmExceptionTrap);
....rest of form creation etc goes here
------------------------------------------------------------------------
---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
------------------------------------------------------------------------
---
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz