-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
namespace WinPowerHelper | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Windows; | ||
using WinPowerHelper.Wpf.Interaction; | ||
|
||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
Startup += (e, args) => | ||
{ | ||
_mutex = new Mutex(true, "WinPowerHelper", out bool isNew); | ||
if (!isNew) | ||
{ | ||
NativeMethods.PostMessage( | ||
(IntPtr)NativeMethods.HWND_BROADCAST, | ||
NativeMethods.WM_SHOWME, | ||
IntPtr.Zero, | ||
IntPtr.Zero); | ||
Environment.Exit(0); | ||
} | ||
}; | ||
} | ||
|
||
private Mutex _mutex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace WinPowerHelper.Wpf.Interaction | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
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", CharSet = CharSet.Unicode)] | ||
public static extern int RegisterWindowMessage(string message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters