Advertisement
Guest User

Move-Shit

a guest
May 26th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. private bool Drag;
  2. private int MouseX;
  3. private int MouseY;
  4.  
  5. private const int WM_NCHITTEST = 0x84;
  6. private const int HTCLIENT = 0x1;
  7. private const int HTCAPTION = 0x2;
  8.  
  9. private bool m_aeroEnabled;
  10.  
  11. private const int CS_DROPSHADOW = 0x00020000;
  12. private const int WM_NCPAINT = 0x0085;
  13.  
  14. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  15. public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
  16. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  17. public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
  18. [System.Runtime.InteropServices.DllImport("dwmapi.dll")]
  19.  
  20. public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
  21. [System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
  22. private static extern IntPtr CreateRoundRectRgn(
  23. int nLeftRect,
  24. int nTopRect,
  25. int nRightRect,
  26. int nBottomRect,
  27. int nWidthEllipse,
  28. int nHeightEllipse
  29. );
  30.  
  31. public struct MARGINS
  32. {
  33. public int leftWidth;
  34. public int rightWidth;
  35. public int topHeight;
  36. public int bottomHeight;
  37. }
  38. protected override CreateParams CreateParams
  39. {
  40. get
  41. {
  42. m_aeroEnabled = CheckAeroEnabled();
  43. CreateParams cp = base.CreateParams;
  44. if (!m_aeroEnabled)
  45. cp.ClassStyle |= CS_DROPSHADOW; return cp;
  46. }
  47. }
  48. private bool CheckAeroEnabled()
  49. {
  50. if (Environment.OSVersion.Version.Major >= 6)
  51. {
  52. int enabled = 0; DwmIsCompositionEnabled(ref enabled);
  53. return (enabled == 1) ? true : false;
  54. }
  55. return false;
  56. }
  57.  
  58. private const int WM_NCLBUTTONDBLCLK = 0x00A3;
  59. protected override void WndProc(ref Message m)
  60. {
  61. if (m.Msg == WM_NCLBUTTONDBLCLK)
  62. {
  63. m.Result = IntPtr.Zero;
  64. return;
  65. }
  66. base.WndProc(ref m);
  67.  
  68. switch (m.Msg)
  69. {
  70. case WM_NCPAINT:
  71. if (m_aeroEnabled)
  72. {
  73. var v = 2;
  74. DwmSetWindowAttribute(Handle, 2, ref v, 4);
  75. MARGINS margins = new MARGINS()
  76. {
  77. bottomHeight = 1,
  78. leftWidth = 0,
  79. rightWidth = 0,
  80. topHeight = 0
  81. }; DwmExtendFrameIntoClientArea(Handle, ref margins);
  82. }
  83. break;
  84. default: break;
  85. }
  86. base.WndProc(ref m);
  87. if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION;
  88. }
  89. private void PanelMove_MouseDown(object sender, MouseEventArgs e)
  90. {
  91. Drag = true;
  92. MouseX = Cursor.Position.X - Left;
  93. MouseY = Cursor.Position.Y - Top;
  94. }
  95. private void PanelMove_MouseMove(object sender, MouseEventArgs e)
  96. {
  97. if (Drag)
  98. {
  99. Top = Cursor.Position.Y - MouseY;
  100. Left = Cursor.Position.X - MouseX;
  101. }
  102. }
  103.  
  104. private void PanelMove_MouseUp(object sender, MouseEventArgs e) { Drag = false; }
  105.  
  106. protected override void OnPaint(PaintEventArgs e)
  107. {
  108. ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.FromArgb(100, 100, 100), ButtonBorderStyle.Solid);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement