Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ScreenDimmer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -79,6 +87,7 @@ internal Configuration()
HotKeyDecreaseBrightness = new GlobalHotKey();
HotKeyForceOnTop = new GlobalHotKey();
HotKeyHalt = new GlobalHotKey();
HotKeyResize = new GlobalHotKey();
}

private void setHotkeyDescriptions()
Expand All @@ -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()
Expand All @@ -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();
}

Expand Down
43 changes: 42 additions & 1 deletion ScreenDimmer/ScreenDimmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -112,7 +145,7 @@ public ScreenDimmer()
/// </summary>
private void initOverlayWindow()
{
overlayWindow = new Form();
overlayWindow = new Form1();
overlayWindow.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
overlayWindow.ShowInTaskbar = false;
overlayWindow.Show();
Expand Down Expand Up @@ -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);
Expand All @@ -166,6 +200,7 @@ private void populateHotkeys()
helpWindow.AddHotKey(configuration.HotKeyDecreaseBrightness);
helpWindow.AddHotKey(configuration.HotKeyForceOnTop);
helpWindow.AddHotKey(configuration.HotKeyHalt);
helpWindow.AddHotKey(configuration.HotKeyResize);
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down