This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/UpToolEto/UpToolEto.Wpf/Program.cs

38 lines
1.1 KiB
C#

using System;
using Eto.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace UpToolEto.Wpf
{
class MainClass
{
[STAThread]
public static void Main(string[] args)
{
new Main(new Application(Eto.Platforms.Wpf), () =>
{
Process[] processes = Process.GetProcessesByName("UpTool2");
if (processes.Length > 0)
BringProcessToFront(processes[0]);
}, args).Entry();
}
public static void BringProcessToFront(Process process)
{
IntPtr handle = process.MainWindowHandle;
if (IsIconic(handle))
ShowWindow(handle, 9);
SetForegroundWindow(handle);
}
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);
}
}