I want to maintain single instane of my application. So I use the following
code.

bool bCreateNew;
string strName = "Temp";

_Mutex = new System.Threading.Mutex(true, strName, out bCreateNew);
if (bCreateNew == false) {
IntPtr hPrePop = FindWindow(null,strWindowName);
if (hPrePop != IntPtr.Zero)
{
//Pop up the previous instance
ShowWindow(hPrePop);
SetForegroundWindow(hPrePop);
}
}

But my application is originally put in the tray, I want the application to
return from tray if the user attempt to open a new instance. So how can I
call the previous instance to set the the visiblity of the tray icon to be
false? What I mean is puting what code inside the if - block (i.e. if
(hPrePop != IntPtr.Zero)) can achieve my goal?

--
Franz Wong
My C++ and C# Site (Traditional Chinese) : http://www.franzwong.com

Re: Solution to maintain single instance by Franz

Franz
Mon Sep 15 12:11:41 CDT 2003

Solved by SendMessage

--
Franz Wong
My C++ and C# Site (Traditional Chinese) : http://www.franzwong.com


"Franz" <honfung3@yahoo.com.hk> ¦b¶l¥ó
news:OmENXB2eDHA.2364@TK2MSFTNGP09.phx.gbl ¤¤¼¶¼g...
> I want to maintain single instane of my application. So I use the
following
> code.
>
> bool bCreateNew;
> string strName = "Temp";
>
> _Mutex = new System.Threading.Mutex(true, strName, out bCreateNew);
> if (bCreateNew == false) {
> IntPtr hPrePop = FindWindow(null,strWindowName);
> if (hPrePop != IntPtr.Zero)
> {
> //Pop up the previous instance
> ShowWindow(hPrePop);
> SetForegroundWindow(hPrePop);
> }
> }
>
> But my application is originally put in the tray, I want the application
to
> return from tray if the user attempt to open a new instance. So how can I
> call the previous instance to set the the visiblity of the tray icon to be
> false? What I mean is puting what code inside the if - block (i.e. if
> (hPrePop != IntPtr.Zero)) can achieve my goal?
>
> --
> Franz Wong
> My C++ and C# Site (Traditional Chinese) : http://www.franzwong.com
>
>
>