S
Steven Van Dyke
I'm using a mutex to ensure only 1 instance of my app is created. It works
fine.
If an instance of my app IS already running, I want to use the following
code to bring the window to the foreground. BUT, the MainWindowHandle is
always 0 (I checked all processes and they are all 0). How can I get the
window handle back? Or, is there another way to popup my application?
Thanks,
Steve
if (!grantedInitialOwnership)
{
Process[] ps =
Process.GetProcessesByName("AppName");
IntPtr hWnd = ps[0].MainWindowHandle;
// Show existing instance
if (hWnd.ToInt64() != 0)
{
SetForegroundWindow(hWnd);
ShowWindow(hWnd, 5); // SW_SHOW
}
}
fine.
If an instance of my app IS already running, I want to use the following
code to bring the window to the foreground. BUT, the MainWindowHandle is
always 0 (I checked all processes and they are all 0). How can I get the
window handle back? Or, is there another way to popup my application?
Thanks,
Steve
if (!grantedInitialOwnership)
{
Process[] ps =
Process.GetProcessesByName("AppName");
IntPtr hWnd = ps[0].MainWindowHandle;
// Show existing instance
if (hWnd.ToInt64() != 0)
{
SetForegroundWindow(hWnd);
ShowWindow(hWnd, 5); // SW_SHOW
}
}