🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

IsIconic returns false when Application is minimised

#7222
From: N Bentley
Date: Sat, 05 Mar 2005 11:34
46 lines
2571 bytes
I am trying to prevent multiple instances of my application using C++ 
Builder 6.

I have done this before with C++ Builder 5 without problem. The code 
template I am using is:

 ::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;
         FirsthWnd = ::FindWindow("TApplication", "YourApplicationTitle"); 
// see Application->Title or Options|Project|Application Tab|Title
         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);
     }

This works fine except when the first Instance is minimised. When loading a 
second instance the code failes to restore the first instance because 
IsIconic always returns false.

Does anyone know why this might be the case.

I'm running on WinXP SP2.

Out of interest if I run a second instance whilst my project is open in BCB6 
with the Main Form's design Window minimised then the Forms design Window is 
restored??


Thanks,

Neville.
Technical Details
Message-ID: <42299944@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e122cfc7c5c02b63,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "N Bentley" <nlb@ntl.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: IsIconic returns false when Application is minimised
Date: Sat, 5 Mar 2005 11:34:18 -0000
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 81.97.143.120
Message-ID: <42299944@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1110022468 81.97.143.120 (5 Mar 2005 03:34:28 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!irazu.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail