-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
59 lines (53 loc) · 1.82 KB
/
App.xaml.cs
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
50
51
52
53
54
55
56
57
58
59
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using NoNote.config;
namespace NoNote
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
[DllImport("user32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (IsRunning())
{
Application.Current.Shutdown();
return;
}
string appDir = AppDomain.CurrentDomain.BaseDirectory;
ConfigUtil.myFolder = appDir;
ConfigUtil.configArray = new ConfigUtil().getConfig();
}
public static bool IsRunning()
{
using (Process current = Process.GetCurrentProcess())
{
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
using (process)
{
if (process.Id == current.Id) continue;
if (process.MainModule.FileName == current.MainModule.FileName)
{
const int SW_RESTORE = 9;
ShowWindowAsync(process.MainWindowHandle, SW_RESTORE);
SetForegroundWindow(process.MainWindowHandle);
return true;
}
}
}
return false;
}
}
}
}