Files
laatzen/Common/Ui/Common.UI/App.xaml.cs
T

39 lines
1.1 KiB
C#

namespace Common.UI
{
using Common.UI.Infrastructure;
using System;
using System.Diagnostics;
using System.Windows;
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
var currentProcess = Process.GetCurrentProcess();
foreach (var process in Process.GetProcessesByName(currentProcess.ProcessName))
{
if (process.Id != currentProcess.Id && process.MainModule.FileName == currentProcess.MainModule.FileName)
{
var windowHandle = process.MainWindowHandle;
if (windowHandle != IntPtr.Zero)
{
if (User32DllImports.IsIconic(windowHandle))
{
User32DllImports.ShowWindow(windowHandle, WindowCommands.Restore);
}
User32DllImports.SetForegroundWindow(windowHandle);
this.Shutdown();
break;
}
}
}
}
}
}