-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropShadowCS.cs
129 lines (117 loc) · 4.06 KB
/
DropShadowCS.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
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DropShadow
{
public class DropShadowCS
{
private bool m_aeroEnabled;
private const int CS_DROPSHADOW = 0x00020000;
[DllImport("dwmapi")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr handle, ref MARGINS pMarInset);
[DllImport("dwmapi")]
private static extern int DwmSetWindowAttribute(IntPtr handle, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi")]
private static extern int DwmIsCompositionEnabled(ref int pfEnabled);
[DllImport("user32")]
private static extern bool ReleaseCapture();
[DllImport("user32")]
private static extern int SendMessage(IntPtr handle, int msg, int wp, int lp);
private struct MARGINS
{
public int LeftWidth;
public int RightWidth;
public int TopHeight;
public int BottomHeight;
}
public CreateParams CreateWNDParams(CreateParams cp)
{
m_aeroEnabled = CheckAeroEnabled();
if (!m_aeroEnabled) cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
public void CreateDropShadow(Form window, Control captionBar)
{
window.Paint += delegate (object sender, PaintEventArgs e)
{
var gfx = e.Graphics;
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(window.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS
{
BottomHeight = 1,
LeftWidth = 0,
RightWidth = 0,
TopHeight = 0
};
DwmExtendFrameIntoClientArea(window.Handle, ref margins);
}
};
captionBar.MouseDown += delegate (object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(window.Handle, 161, 2, 0);
};
}
public void CreateDropShadow(Form window, Control[] captionControls)
{
window.Paint += delegate (object sender, PaintEventArgs e)
{
var gfx = e.Graphics;
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(window.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS
{
BottomHeight = 1,
LeftWidth = 0,
RightWidth = 0,
TopHeight = 0
};
DwmExtendFrameIntoClientArea(window.Handle, ref margins);
}
};
foreach (Control captionControl in captionControls)
{
captionControl.MouseDown += delegate (object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(window.Handle, 161, 2, 0);
};
}
}
public void CreateDropShadow(Control control)
{
control.Paint += delegate (object sender, PaintEventArgs e)
{
var gfx = e.Graphics;
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(control.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS
{
BottomHeight = 1,
LeftWidth = 0,
RightWidth = 0,
TopHeight = 0
};
DwmExtendFrameIntoClientArea(control.Handle, ref margins);
}
};
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0;
DwmIsCompositionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
}
}