the_alex_mark

Тень у "Form"

Mar 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. #region Shadow
  2.  
  3. private const int WM_NCHITTEST = 0x84;
  4. private const int HTCLIENT = 0x1;
  5. private const int HTCAPTION = 0x2;
  6. private bool m_aeroEnabled;
  7. private const int CS_DROPSHADOW = 0x00020000;
  8. private const int WM_NCPAINT = 0x0085;
  9. private const int WM_ACTIVATEAPP = 0x001C;
  10.  
  11. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  12. public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
  13. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  14. public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
  15. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  16.  
  17. public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
  18. [System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
  19. private static extern IntPtr CreateRoundRectRgn(
  20.     Int32 nLeftRect, Int32 nTopRect, Int32 nRightRect, Int32 nBottomRect, Int32 nWidthEllipse, Int32 nHeightEllipse);
  21.  
  22. public struct MARGINS
  23. {
  24.     public int leftWidth;
  25.     public int rightWidth;
  26.     public int topHeight;
  27.     public int bottomHeight;
  28. }
  29. protected override CreateParams CreateParams
  30. {
  31.     get
  32.     {
  33.         m_aeroEnabled = CheckAeroEnabled();
  34.         CreateParams cp = base.CreateParams;
  35.         if (!m_aeroEnabled)
  36.             cp.ClassStyle |= CS_DROPSHADOW; return cp;
  37.     }
  38. }
  39. private bool CheckAeroEnabled()
  40. {
  41.     if (Environment.OSVersion.Version.Major >= 6)
  42.     {
  43.         int enabled = 0; DwmIsCompositionEnabled(ref enabled);
  44.         return (enabled == 1) ? true : false;
  45.     }
  46.     return false;
  47. }
  48. protected override void WndProc(ref Message e)
  49. {
  50.     switch (e.Msg)
  51.     {
  52.         case WM_NCPAINT:
  53.             if (m_aeroEnabled)
  54.             {
  55.                 var v = 2;
  56.                 DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
  57.                 MARGINS margins = new MARGINS()
  58.                 {
  59.                     bottomHeight = 1,
  60.                     leftWidth = 0,
  61.                     rightWidth = 0,
  62.                     topHeight = 0
  63.                 };
  64.                 DwmExtendFrameIntoClientArea(this.Handle, ref margins);
  65.             }
  66.             break;
  67.  
  68.         default: break;
  69.     }
  70.     base.WndProc(ref e);
  71. }
  72.  
  73. #endregion
Add Comment
Please, Sign In to add comment