-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProgram.cs
58 lines (50 loc) · 1.9 KB
/
Program.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
using System;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
namespace iMon.XBMC
{
static class Program
{
static Mutex mutex = new Mutex(true, Application.ProductName);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
if (mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new XBMC());
mutex.ReleaseMutex();
}
else
{
// send our Win32 message to make the currently running instance
// jump on top of all the other windows
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero);
}
}
catch (Exception ex)
{
Logging.Error("Unhandled exception", ex);
MessageBox.Show("An unhandled exception has occured." + Environment.NewLine +
"Please check the debug/error log for more details", "Unhandled Exception",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
internal class NativeMethods
{
public const int HWND_BROADCAST = 0xffff;
public static readonly int WM_SHOWME = RegisterWindowMessage("WM_SHOWME");
[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
[DllImport("user32")]
public static extern int RegisterWindowMessage(string message);
}
}
}