Im trying to make my programm behave like others (e.g. Steam) do. If the program is minimized and you start the .exe of it again, it shouldnt start a second instance, but maximise the first one. I already archived that with a little use of the winapi (User32.dll) like this:
if (AlreadyRunning(ref secondProcess))
{
if(secondProcess != null)
{
//forces a minimize
ShowWindow(secondProcess.MainWindowHandle, 11);
//shows the window
ShowWindow(secondProcess.MainWindowHandle, 1);
}
//Stops the second instance
Process.GetCurrentProcess().Kill();
}
The problem I now have is, that my programm often runs with Visibillity = Visibility.Hidden on the MainWindow. When this is the case and the function^ gets called, nothing happens. I have no idea how to change the property from the outside.