forked from crosire/reshade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlass.cs
113 lines (93 loc) · 3.06 KB
/
Glass.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
public static class Glass
{
[StructLayout(LayoutKind.Sequential)]
private struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("dwmapi.dll")]
private static extern int DwmIsCompositionEnabled(out bool enabled);
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hwnd, int index);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
public static bool IsEnabled
{
get
{
bool enabled = false;
DwmIsCompositionEnabled(out enabled);
return enabled;
}
}
public static void HideIcon(Window window)
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
const int WM_SETICON = 0x0080;
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
const int GWL_EXSTYLE = -20;
const int WS_EX_DLGMODALFRAME = 0x0001;
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME);
const int SWP_NOSIZE = 0x0001;
const int SWP_NOMOVE = 0x0002;
const int SWP_NOZORDER = 0x0004;
const int SWP_FRAMECHANGED = 0x0020;
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
public static void HideSystemMenu(Window window, bool hidden = true)
{
IntPtr hwnd = new WindowInteropHelper(window).Handle;
const int GWL_STYLE = -16;
const int WS_SYSMENU = 0x80000;
if (hidden)
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
else
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_SYSMENU);
}
}
public static bool ExtendFrame(Window window)
{
return ExtendFrame(window, new Thickness(-1, -1, -1, -1));
}
public static bool ExtendFrame(Window window, Thickness margin)
{
if (!IsEnabled)
{
return false;
}
IntPtr hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero)
{
throw new InvalidOperationException("The window must be shown before extending glass effect.");
}
// Adapted from http://blogs.msdn.com/b/adam_nathan/archive/2006/05/04/589686.aspx
window.Background = Brushes.Transparent;
HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
var margins = new MARGINS {
cxLeftWidth = (int)margin.Left,
cxRightWidth = (int)margin.Right,
cyTopHeight = (int)margin.Top,
cyBottomHeight = (int)margin.Bottom
};
DwmExtendFrameIntoClientArea(hwnd, ref margins);
return true;
}
}