-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (39 loc) · 1.33 KB
/
Program.cs
File metadata and controls
49 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Runtime.InteropServices;
namespace OriApps.ResumeBoost;
static class Program
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindow(string? lpClassName, string? lpWindowName);
[DllImport("user32.dll")]
private static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private static Mutex? _mutex;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (TryPreventSecondInstance())
{
return;
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new MainForm());
}
private static bool TryPreventSecondInstance()
{
_mutex = new Mutex(true, "OriApps.ResumeBoost.Mutex", out bool createdNew);
if (!createdNew)
{
IntPtr hWnd = FindWindow(null, "Resume Boost");
if (hWnd != IntPtr.Zero)
{
PostMessage(hWnd, MainForm.WM_SHOWMAIN, IntPtr.Zero, IntPtr.Zero);
}
return true;
}
return false;
}
}