diff --git a/ScreenDimmer/Configuration.cs b/ScreenDimmer/Configuration.cs index fc75e18..069bd99 100644 --- a/ScreenDimmer/Configuration.cs +++ b/ScreenDimmer/Configuration.cs @@ -71,6 +71,14 @@ private string hotKeyHalt { set { HotKeyHalt = GlobalHotkeyParser.Parse(value); } } internal GlobalHotKey HotKeyHalt; + [DataMember(Name = "HotkeyResize")] + private string hotKeyResize + { + get { return HotKeyResize.ToString(); } + set { HotKeyResize = GlobalHotkeyParser.Parse(value); } + } + internal GlobalHotKey HotKeyResize; + internal Configuration() { HotKeyDim = new GlobalHotKey(); @@ -79,6 +87,7 @@ internal Configuration() HotKeyDecreaseBrightness = new GlobalHotKey(); HotKeyForceOnTop = new GlobalHotKey(); HotKeyHalt = new GlobalHotKey(); + HotKeyResize = new GlobalHotKey(); } private void setHotkeyDescriptions() @@ -89,6 +98,7 @@ private void setHotkeyDescriptions() HotKeyDecreaseBrightness.SetDescription("Decrease Brightness"); HotKeyForceOnTop.SetDescription("Force on Top"); HotKeyHalt.SetDescription("Immediately Halt Program"); + HotKeyResize.SetDescription("Adjust Window Size"); } internal void LoadDefault() @@ -107,6 +117,7 @@ internal void LoadDefault() HotKeyIncreaseBrightness.SetKey(KeyModifiers.MOD_WIN | KeyModifiers.MOD_CONTROL, System.Windows.Forms.Keys.Up); HotKeyForceOnTop.SetKey(KeyModifiers.MOD_WIN | KeyModifiers.MOD_CONTROL, System.Windows.Forms.Keys.T); HotKeyHalt.SetKey(KeyModifiers.MOD_WIN | KeyModifiers.MOD_CONTROL, System.Windows.Forms.Keys.H); + HotKeyResize.SetKey(KeyModifiers.MOD_WIN | KeyModifiers.MOD_CONTROL, System.Windows.Forms.Keys.B); setHotkeyDescriptions(); } diff --git a/ScreenDimmer/ScreenDimmer.cs b/ScreenDimmer/ScreenDimmer.cs index 3fed4cf..a8a3a62 100644 --- a/ScreenDimmer/ScreenDimmer.cs +++ b/ScreenDimmer/ScreenDimmer.cs @@ -87,6 +87,39 @@ internal partial class ScreenDimmer : Form public static readonly Icon IconMediumBright32x32 = TextIcon.CreateTextIcon("\uE286", Color.White, "", 32); #endregion + public partial class Form1 : Form + { + public Form1() + { + //InitializeComponent(); + } + + const int WM_NCHITTEST = 0x0084; + const int HTCLIENT = 1; + const int HTCAPTION = 2; + protected override void WndProc(ref Message m) + { + base.WndProc(ref m); + switch (m.Msg) + { + case WM_NCHITTEST: + if (m.Result == (IntPtr)HTCLIENT) + { + var p = this.PointToClient(new Point(m.LParam.ToInt32())); + + m.Result = + (IntPtr) + (p.X <= 6 + ? p.Y <= 6 ? 13 : p.Y >= this.Height - 7 ? 16 : 10 + : p.X >= this.Width - 7 + ? p.Y <= 6 ? 14 : p.Y >= this.Height - 7 ? 17 : 11 + : p.Y <= 6 ? 12 : p.Y >= this.Height - 7 ? 15 : p.Y <= 24 ? 2 : 1); + } + break; + } + } + } + public ScreenDimmer() { InitializeComponent(); @@ -112,7 +145,7 @@ public ScreenDimmer() /// private void initOverlayWindow() { - overlayWindow = new Form(); + overlayWindow = new Form1(); overlayWindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; overlayWindow.ShowInTaskbar = false; overlayWindow.Show(); @@ -148,6 +181,7 @@ private void hookKeys() success &= tryHookKeyAppendError(configuration.HotKeyDim, ref sb); success &= tryHookKeyAppendError(configuration.HotKeyForceOnTop, ref sb); success &= tryHookKeyAppendError(configuration.HotKeyHalt, ref sb); + success &= tryHookKeyAppendError(configuration.HotKeyResize, ref sb); if (!success) { notifyIcon1.ShowBalloonTip(0, "Cannot register one or more hotkeys.", sb.ToString(), ToolTipIcon.Warning); @@ -166,6 +200,7 @@ private void populateHotkeys() helpWindow.AddHotKey(configuration.HotKeyDecreaseBrightness); helpWindow.AddHotKey(configuration.HotKeyForceOnTop); helpWindow.AddHotKey(configuration.HotKeyHalt); + helpWindow.AddHotKey(configuration.HotKeyResize); } /// @@ -235,6 +270,12 @@ protected override void WndProc(ref Message m) isContextClose = true; Close(); } + else if (hotkeyId == configuration.HotKeyResize.Id) + { + NativeMethods.SetWindowLong(overlayWindow.Handle, NativeMethods.GWL_EXSTYLE, + NativeMethods.GetWindowLong(overlayWindow.Handle, NativeMethods.GWL_EXSTYLE) + ^ (int)ExtendedWindowStyles.WS_EX_TRANSPARENT); + } break; } base.WndProc(ref m);