🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Activating the first instance of a program when it's started multiple times

#6669
From: Alan Bellingham
Date: Fri, 22 Apr 2005 10:21
28 lines
1950 bytes
"SubZero" <g_ates@hotmail.com> wrote:

>I have a program that I want it to act like Outlook Express in the sense 
>that when the program is minimized or in the tray, and when user clicks on 
>the desktop icon, instead of relaunching a second instance, it should bring 
>the first instance to screen (window should be visible).

A possibility.

When your program starts, use RegisterWindowMessage() to generate a
special unique-to-you Windows message ID.

Then attempt to create a mutex. If it is created successfully, then
you're the original copy, so run as normal. (Don't forget to release it
at the end.)

If you failed, you're the copy. So use EnumWindows to find all top-level
windows in turn, and send the message to each of them. And then
terminate. Or send it to HWND_BROADCAST (simpler).

Meanwhile, when the original receives the message, it knows that it
should pop up and show itself.

Note - I've not explicitly done this.

Alan Bellingham
-- 
ACCU Conference 2005 - 20-23 April, Randolph Hotel, Oxford, UK
Technical Details
Message-ID: <hjjh611ts968n1t3fi1gmideur5oav2bsr@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42688891@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,3c4287e4044a862e
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Alan Bellingham <alanb@episys.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Activating the first instance of a program when it's started multiple times
Date: Fri, 22 Apr 2005 11:21:06 +0100
Reply-To: alanb@episys.com
Message-ID: <hjjh611ts968n1t3fi1gmideur5oav2bsr@4ax.com>
References: <42688891@newsgroups.borland.com>
X-Newsreader: Forte Agent 2.0/32.652
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 193.129.251.253
X-Trace: newsgroups.borland.com 1114165266 193.129.251.253 (22 Apr 2005 03:21:06 -0700)
Lines: 28
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail