-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
48 lines (42 loc) · 1.39 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
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
namespace DanmukuRPCServer
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
[DllImport("user32", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(string cls, string win);
[DllImport("user32")]
static extern IntPtr SetForegroundWindow(IntPtr hWnd);
[DllImport("user32")]
static extern bool IsIconic(IntPtr hWnd);
[DllImport("user32")]
static extern bool OpenIcon(IntPtr hWnd);
static Mutex singleton;
public App()
{
Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(this.App_DispatcherUnhandledException);
}
protected override void OnStartup(StartupEventArgs e)
{
bool isNew;
singleton = new Mutex(true, "DanmukuRPCServer_bajdcc", out isNew);
if (!isNew)
{
Shutdown();
return;
}
base.OnStartup(e);
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(Application.Current.MainWindow, e.Exception.ToString());
}
}
}