-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDimWindow.cs
37 lines (31 loc) · 1.13 KB
/
DimWindow.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
using System;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace PowerDimmer
{
public partial class DimWindow : Window
{
public IntPtr Handle;
public DimWindow(ISettings settings)
{
ShowInTaskbar = false;
AllowsTransparency = true;
Background = Brushes.Black;
WindowStyle = WindowStyle.None;
ResizeMode = ResizeMode.NoResize;
// Seems to be required in order for multiple
// monitor support to work. Otherwise dim window
// remains on primary display in some cases.
Width = 1; Height = 1;
}
protected override void OnSourceInitialized(EventArgs e)
{
Handle = new WindowInteropHelper(this).EnsureHandle();
var style = Win32.GetWindowLong(Handle, Win32.GWL_EXSTYLE);
Win32.SetWindowLong(Handle, Win32.GWL_EXSTYLE, style | Win32.WS_EX_LAYERED | Win32.WS_EX_TRANSPARENT | Win32.WS_EX_NOACTIVATE);
Win32.ShowWindow(Handle, Win32.SW_SHOWMAXIMIZED);
base.OnSourceInitialized(e);
}
}
}