Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Shadow
- private const int WM_NCHITTEST = 0x84;
- private const int HTCLIENT = 0x1;
- private const int HTCAPTION = 0x2;
- private bool m_aeroEnabled;
- private const int CS_DROPSHADOW = 0x00020000;
- private const int WM_NCPAINT = 0x0085;
- private const int WM_ACTIVATEAPP = 0x001C;
- [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
- public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
- [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
- public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
- [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
- public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
- [System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
- private static extern IntPtr CreateRoundRectRgn(
- Int32 nLeftRect, Int32 nTopRect, Int32 nRightRect, Int32 nBottomRect, Int32 nWidthEllipse, Int32 nHeightEllipse);
- public struct MARGINS
- {
- public int leftWidth;
- public int rightWidth;
- public int topHeight;
- public int bottomHeight;
- }
- protected override CreateParams CreateParams
- {
- get
- {
- m_aeroEnabled = CheckAeroEnabled();
- CreateParams cp = base.CreateParams;
- if (!m_aeroEnabled)
- cp.ClassStyle |= CS_DROPSHADOW; return cp;
- }
- }
- private bool CheckAeroEnabled()
- {
- if (Environment.OSVersion.Version.Major >= 6)
- {
- int enabled = 0; DwmIsCompositionEnabled(ref enabled);
- return (enabled == 1) ? true : false;
- }
- return false;
- }
- protected override void WndProc(ref Message e)
- {
- switch (e.Msg)
- {
- case WM_NCPAINT:
- if (m_aeroEnabled)
- {
- var v = 2;
- DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
- MARGINS margins = new MARGINS()
- {
- bottomHeight = 1,
- leftWidth = 0,
- rightWidth = 0,
- topHeight = 0
- };
- DwmExtendFrameIntoClientArea(this.Handle, ref margins);
- }
- break;
- default: break;
- }
- base.WndProc(ref e);
- }
- #endregion
Add Comment
Please, Sign In to add comment