Widow
/trunk/Widow/Constants.cs |
@@ -1,4 +1,5 @@ |
using System.Reflection; |
using System.Runtime.InteropServices; |
|
namespace Widow |
{ |
@@ -10,6 +11,9 @@ |
|
public static readonly string AssemblyVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); |
|
public static readonly string AssemblyGuid = |
((GuidAttribute) Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value; |
|
#endregion |
} |
} |
/trunk/Widow/Natives.cs |
@@ -7,6 +7,14 @@ |
{ |
public static class Natives |
{ |
#region Static Fields and Constants |
|
public const int HWND_BROADCAST = 0xffff; |
|
public static readonly int WM_SHOWME = RegisterWindowMessage("WM_SHOWME"); |
|
#endregion |
|
#region Public Events & Delegates |
|
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); |
@@ -1589,6 +1597,9 @@ |
|
#region Public Methods |
|
[DllImport("user32")] |
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); |
|
[DllImport("user32.dll")] |
public static extern IntPtr WindowFromPoint(Point p); |
|
/trunk/Widow/Program.cs |
@@ -1,4 +1,5 @@ |
using System; |
using System.Threading; |
using System.Windows.Forms; |
|
namespace Widow |
@@ -7,6 +8,8 @@ |
{ |
#region Static Fields and Constants |
|
private static readonly Mutex Mutex = new Mutex(true, Constants.AssemblyGuid); |
|
private static Form _form; |
|
#endregion |
@@ -29,10 +32,21 @@ |
[STAThread] |
private static void Main() |
{ |
Application.EnableVisualStyles(); |
Application.SetCompatibleTextRenderingDefault(false); |
_form = new MainForm(); |
Application.Run(); |
if (Mutex.WaitOne(TimeSpan.Zero, true)) |
{ |
Application.SetCompatibleTextRenderingDefault(false); |
_form = new MainForm(); |
Application.Run(); |
Mutex.ReleaseMutex(); |
return; |
} |
|
// Foreground current other application window. |
Natives.PostMessage( |
(IntPtr) Natives.HWND_BROADCAST, |
Natives.WM_SHOWME, |
IntPtr.Zero, |
IntPtr.Zero); |
} |
|
#endregion |