🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8273

Re: processinformation

#8273
From: Paolo Borlandi
Date: Tue, 09 Nov 2004 13:04
87 lines
3143 bytes
"luca casotti" <lucacasotti@libero.it> ha scritto nel messaggio 
news:4190b40a$1@newsgroups.borland.com...
> when a process starts, how can it know if there is another his instance
> already running?
>
>


FAQ3816C.txt   Preventing multiple instances with BCB

            Category   :Windows API

            Product    :   All32Bit



            Question:

            I want to permit only one copy of my program to run at a time. 
The Previous

            Instance is always set to NULL, yet it is supposed to be NULL 
only the first

            time you run the program.



            Answer:

            This is a code example of using a Mutex to determine if another

            instance is running.



            ::CreateMutex(NULL, FALSE, "YourMutexName");

                if ( GetlastError() == ERROR_ALREADY_EXISTS )

                {

                    // Found another running application with the same mutex

                    // so one instance is already running.

                    Application->Title="Testing";  // prohibits finding this 
instance

                    HWND FirsthWnd, FirstChildhWnd;

                    // see Application->Title or Options|Project|Application 
Tab|Title

                    FirsthWnd = ::FindWindow("TApplication", 
"YourApplicationTitle");

                    if (::IsIconic(FirsthWnd))

                        ::ShowWindow(FirsthWnd, SW_SHOWDEFAULT);

                    ::SetForegroundWindow(FirsthWnd);

                    FirstChildhWnd = ::GetLastActivePopup(FirsthWnd);

                    if (FirsthWnd != FirstChildhWnd)

                        ::BringWindowToTop(FirstChildhWnd); // A pop-up is 
active so bring it to the top too.

                }

                else

                {

                    Application->Initialize();

                    Application->Title = "YourApplicationTitle";

                    Application->CreateForm(__classid(TYourAppMainForm),&YourAppMainForm);

                }


Good Luck
Paolo Borlandi
Technical Details
Message-ID: <4190c07c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4190b40a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ac5df4e852a37c85
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Paolo Borlandi" <pborlandi@virgilio.it>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4190b40a$1@newsgroups.borland.com>
Subject: Re: processinformation
Date: Tue, 9 Nov 2004 14:04:47 +0100
Lines: 90
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.48.5.157
Message-ID: <4190c07c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1100005500 82.48.5.157 (9 Nov 2004 05:05:00 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!zen.net.uk!dedekind.zen.co.uk!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail