Article View: borland.public.cppbuilder.nativeapi
Article #6601Re: Start an exe only one time
From: Mark Jacobs
Date: Tue, 26 Apr 2005 09:45
Date: Tue, 26 Apr 2005 09:45
29 lines
2035 bytes
2035 bytes
Dani wrote:
> I am developing an appliction and I want that it can be started only one time.
> How can I do that?
AnsiString titlkfr; HWND winhdlfnd;
BOOL CALLBACK mjEnumWindowspork(HWND hwnd,LPARAM lParam)
{
char mjbf[99];
mjbf[0]='\0'; GetWindowText(hwnd,mjbf,98); mjbf[titlkfr.Length()]='\0';
if (stricmp(mjbf,titlkfr.c_str())==0) { winhdlfnd=hwnd; return FALSE;}
return TRUE;
}
HWND mjlocatewindow(AnsiString tittxt)
{
winhdlfnd=NULL; titlkfr=tittxt.SubString(1,90);
EnumWindows((WNDENUMPROC)mjEnumWindowspork,999);
return winhdlfnd;
}
In your app, call mjlocatewindow("MyProg"); and if it is non-NULL, then an
instance is already running. There is a trick you must play first, though. You
must name your app "Not Yet MyProg", and after it has loaded successfully,
then set Application->Title to MyProg. This is so it does not detect itself
when loading up.
--
Mark Jacobs
http://www.dkcomputing.co.uk
Technical Details
Message-ID:
<426e0dc2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<426a8aa4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d20d2256af9a446f X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 26 Apr 2005 10:45:40 +0100 From: Mark Jacobs <http://www.jacobsm.com/mjmsg.htm?mj@critical> User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Start an exe only one time References: <426a8aa4$1@newsgroups.borland.com> In-Reply-To: <426a8aa4$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 81.144.157.8 Message-ID: <426e0dc2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1114508738 81.144.157.8 (26 Apr 2005 02:45:38 -0700) Lines: 29 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail