Chris:
Actually, I've witnessed two apps running using Task Manager. I added code
to my app to search for my open window and to bring that window to the front
and close the new app. This is only successful in closing the new app. My
existing window is not brought to the fore. Here is the code I added to my
main method to control this issue:
string appname =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
splash.lMutex = CreateMutex(IntPtr.Zero, true, appname);
if( !lMutex.Equals(new System.IntPtr(0) ) )
{
if(Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS)
{
// need to find the splash window (not posting my actual window
classname or title
IntPtr hFrmMain = FindWindow("{my_window_classname}",
"{my_window_title}");
if(hFrmMain != IntPtr.Zero)
{
// bring that window to front
SetForegroundWindow(hFrmMain);
// exit this application
return;
}
else
{
hFrmMain = IntPtr.Zero;
// check to see if my other window is opened
hFrmMain = FindWindow("{my_other_window_classname}",
"{my_other_window_title}");
if(hFrmMain != IntPtr.Zero)
{
// bring that window to front
SetForegroundWindow(hFrmMain);
// exit this application
return;
}
}
}
}
// run the app (neither the splash window nor the other window are open)
Application.Run(new splash());
Do you see any logic errors?
Tim
> So is it launching a second instance, of just not bringing the existing
> instance to the fore?
[quoted text clipped - 31 lines]
>>>>
>>>> Tim
Alex Feinman [MVP] - 25 Apr 2006 19:25 GMT
Try using HWND | 0x1 as a parameter to SetForegroundWindow.
> Chris:
>
[quoted text clipped - 84 lines]
>>>>>
>>>>> Tim
Tim Wallace - 25 Apr 2006 20:41 GMT
Alex:
I added the 0x1 to the handle (I had to convert the IntPtr to an Int32, do
the |0x1 and convert back to IntPtr). Still, not luck.
Tim
> Try using HWND | 0x1 as a parameter to SetForegroundWindow.
>
[quoted text clipped - 86 lines]
>>>>>>
>>>>>> Tim
Tim Wallace - 25 Apr 2006 19:27 GMT
Let me add that the code I added will not bring either of my windows to the
top.
Tim
> Chris:
>
[quoted text clipped - 84 lines]
>>>>>
>>>>> Tim