Article View: borland.public.cppbuilder.nativeapi
Article #6673Re: Avoiding multiple programinstances and restore the firstone
From: Vladimir Stefanovic
Date: Fri, 22 Apr 2005 13:42
Date: Fri, 22 Apr 2005 13:42
43 lines
1986 bytes
1986 bytes
Hi Hans,
> If you want to avoid multiple programinstances and/or restore
> the firstone then you can use code below.
What the word firstone means? Really (not a joke), it's not in my
dictionary...
> The use of a mutex and after that searching for windows
> would be doing twice nearly the same.
Yes. I use this, but not sure if that's the best way:
bool StartNewInstance( AnsiString NAME, AnsiString MUTEX )
{
::CreateMutex( NULL, NULL, MUTEX.c_str() );
if ( GetLastError() )
{
Application->Title = "Something different";
HWND FirstWnd;
FirstWnd = ::FindWindow( "TApplication", NAME.c_str() );
if ( ::IsIconic( FirstWnd ) ) ::ShowWindow( FirstWnd,
SW_SHOWDEFAULT );
::SetForegroundWindow( FirstWnd );
return ( false );
}
return ( true );
}
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
if ( ! StartNewInstance( "program", "notprogram" ) )
return 0;
// etc...
--
Best regards,
Vladimir Stefanovic
Technical Details
Message-ID:
<4268ff3a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4268dde6$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fd5c6cb9a40ec609 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Newsgroups: borland.public.cppbuilder.nativeapi References: <4268dde6$1@newsgroups.borland.com> Subject: Re: Avoiding multiple programinstances and restore the firstone Date: Fri, 22 Apr 2005 15:42:30 +0200 Lines: 46 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 82.117.212.65 Message-ID: <4268ff3a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1114177338 82.117.212.65 (22 Apr 2005 06:42:18 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail