-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDwmApi.cs
173 lines (153 loc) · 5.89 KB
/
DwmApi.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* DWM API wrapper
*
* License: CC0, https://creativecommons.org/publicdomain/zero/1.0/
*
* Author: Kirurobo, http://twitter.com/kirurobo
* Author: Ru--en, http://twitter.com/ru__en
* Reference: Ron Fosner, http://msdn.microsoft.com/ja-jp/magazine/cc163435.aspx
*/
using System;
using System.Runtime.InteropServices;
namespace Kirurobo
{
/// <summary>
/// A wrapper of Desktop Window Manager (DWM) API dwmapi.h
/// </summary>
class DwmApi
{
#region Some additional structures
/// <summary>
/// RECT structure defined in windef.h
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 16)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
/// <summary>
/// MARGINS structure defined in uxtheme.h
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 16)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
public MARGINS(int left, int top, int right, int bottom)
{
cxLeftWidth = left;
cyTopHeight = top;
cxRightWidth = right;
cyBottomHeight = bottom;
}
}
#endregion
#region APIs defined in dwmapi.h
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DWM_BLURBEHIND
{
public uint dwFlags;
[MarshalAs(UnmanagedType.Bool)] public bool fEnable;
public RECT? hRgnBlur;
[MarshalAs(UnmanagedType.Bool)] public bool fTransitionOnMaximized;
// Blur behind flags.
public const uint DWM_BB_ENABLE = 0x00000001;
public const uint DWM_BB_BLURREGION = 0x00000002;
public const uint DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DWM_THUMBNAIL_PROPERTIES
{
public uint dwFlags;
public RECT rcDestination;
public RECT rcSource;
public byte opacity;
[MarshalAs(UnmanagedType.Bool)] public bool fVisible;
[MarshalAs(UnmanagedType.Bool)] public bool fSourceClientAreaOnly;
// Thumbnail property flags.
public const uint DWM_TNP_RECTDESTINATION = 0x00000001;
public const uint DWM_TNP_RECTSOURCE = 0x00000002;
public const uint DWM_TNP_OPACITY = 0x00000004;
public const uint DWM_TNP_VISIBLE = 0x00000008;
public const uint DWM_TNP_SOURCECLIENTAREAONLY = 0x00000010;
}
public enum DWMWINDOWATTRIBUTE
{
DWMWA_NCRENDERING_ENABLED = 1,
DWMWA_NCRENDERING_POLICY = 2,
DWMWA_TRANSITIONS_FORCEDISABLED = 3,
DWMWA_ALLOW_NCPAINT = 4,
DWMWA_CAPTION_BUTTON_BOUNDS = 5,
DWMWA_NONCLIENT_RTL_LAYOUT = 6,
DWMWA_FORCE_ICONIC_REPRESENTATION = 7,
DWMWA_FLIP3D_POLICY = 8,
DWMWA_EXTENDED_FRAME_BOUNDS = 9,
DWMWA_HAS_ICONIC_BITMAP = 10,
DWMWA_DISALLOW_PEEK = 11,
DWMWA_EXCLUDED_FROM_PEEK = 12,
DWMWA_CLOAK = 13,
DWMWA_CLOAKED = 14,
DWMWA_FREEZE_REPRESENTATION = 15,
DWMWA_PASSIVE_UPDATE_MODE = 16,
DWMWA_LAST = 17,
}
public enum DWMNCRENDERINGPOLICY
{
DWMNCRP_USEWINDOWSTYLE = 0,
DWMNCRP_DISABLED = 1,
DWMNCRP_ENABLED = 2,
DWMNCRP_LAST = 3,
}
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
[DllImport("dwmapi.dll", PreserveSig = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableComposition(bool bEnable);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmGetColorizationColor(
out int pcrColorization,
[MarshalAs(UnmanagedType.Bool)]out bool pfOpaqueBlend
);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern IntPtr DwmRegisterThumbnail(IntPtr dest, IntPtr source);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmUnregisterThumbnail(IntPtr hThumbnail);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmUpdateThumbnailProperties(IntPtr hThumbnail, DWM_THUMBNAIL_PROPERTIES props);
/// <summary>
/// Apply glass effect to specified margins
/// </summary>
/// <param name="hWnd"></param>
/// <param name="pMargins"></param>
/// <returns></returns>
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
#endregion
#region Original method
/// <summary>
/// Apply glass effect to all client area
/// </summary>
/// <param name="hwnd"></param>
/// <returns></returns>
public static void DwmExtendIntoClientAll(IntPtr hWnd)
{
MARGINS margins = new MARGINS(-1, -1, -1, -1);
DwmExtendFrameIntoClientArea(hWnd, ref margins);
}
#endregion
}
}