🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Avoiding multiple programinstances and restore the firstone

#6672
From: Hans Galema
Date: Fri, 22 Apr 2005 13:56
61 lines
2627 bytes
Vladimir Stefanovic wrote:

> What the word firstone means? Really (not a joke), it's not in my
> dictionary...

Maybe it is not a word (English is not my native language either,
so please correct me).

I meant 'the first'.

Example:
Q: About which instance are you speaking ?
Possible answers:
A: The one which started first.
A: The first one.
A: The firstone.
A: The first.

>>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 )

You did not set back the original Title. That is needed
in case it is the first instance.

What I meant was that you can omit the mutex: (untested)

bool StartNewInstance( AnsiString NAME, AnsiString MUTEX )
{
       AnsiString OldTitle =  Application->Title;

       Application->Title = "Something different";
       HWND FirstWnd;
       FirstWnd = ::FindWindow( "TApplication", NAME.c_str() );
       // TApplication ???

       if ( FirstWnd )
	{
       	if ( ::IsIconic( FirstWnd ) ) ::ShowWindow( FirstWnd,
		SW_SHOWDEFAULT );
       	::SetForegroundWindow( FirstWnd );
       	
	Application->Title = OldTitle;

         return ( false );
         }

      Application->Title = OldTitle;

    return ( true );
}

But my code comes in handy when the Title is not know.
And it does not require changing of stringcontents for
different projects.


Hans.
Technical Details
Message-ID: <42690325$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!proxad.net!gatel-ffm!gatel-ffm!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
References: <4268dde6$1@newsgroups.borland.com> <4268ff3a$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
Date: Fri, 22 Apr 2005 15:56:26 +0200
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Avoiding multiple programinstances and restore the firstone
References: <4268dde6$1@newsgroups.borland.com> <4268ff3a$1@newsgroups.borland.com>
In-Reply-To: <4268ff3a$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 129.125.201.248
Message-ID: <42690325$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1114178341 129.125.201.248 (22 Apr 2005 06:59:01 -0700)
Lines: 61
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!proxad.net!gatel-ffm!gatel-ffm!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