Add project
This commit is contained in:
52
src/Program.cs
Executable file
52
src/Program.cs
Executable file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Program_Hide
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
///
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
|
||||
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
bool createdNew = true;
|
||||
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
|
||||
{
|
||||
if (createdNew)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
else
|
||||
{
|
||||
Process current = Process.GetCurrentProcess();
|
||||
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
|
||||
{
|
||||
if (process.Id != current.Id)
|
||||
{
|
||||
SetForegroundWindow(process.MainWindowHandle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user