using System;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
namespace DevComponents.DotNetBar.Schedule
{
    internal class WinApi
    {
        #region Windows Messages
        public enum WindowsMessages
        {
            WM_NCPAINT = 0x0085,
            WM_NCCALCSIZE = 0x0083,
            WM_NCACTIVATE = 0x0086,
            WM_SETTEXT = 0x000C,
            WM_INITMENUPOPUP = 0x0117,
            WM_WINDOWPOSCHANGED = 0x0047,
            WM_NCHITTEST = 0x0084,
            WM_ERASEBKGND = 0x0014,
            WM_NCMOUSEMOVE = 0xA0,
            WM_NCLBUTTONDOWN = 0xA1,
            WM_NCMOUSELEAVE = 0x2A2,
            WM_NCLBUTTONUP = 0xA2,
            WM_NCMOUSEHOVER = 0x2A0,
            WM_SETCURSOR = 0x20,
            WM_SETICON = 0x0080,
            WM_HSCROLL = 0x0114,
            WM_VSCROLL = 0x115,
            WM_MOUSEWHEEL = 0x020A,
            WM_STYLECHANGED = 0x7D,
            WM_NCLBUTTONDBLCLK = 0xA3,
            WM_MOUSEACTIVATE = 0x21,
            WM_MOUSEMOVE = 0x0200,
            WM_MDISETMENU = 0x230,
            WM_MDIREFRESHMENU = 0x234,
            WM_KEYDOWN = 0x0100,
            WM_SIZE = 0x5,
            WM_DWMCOMPOSITIONCHANGED = 0x031E,
            WM_DRAWITEM = 0x002B,
            SBM_SETPOS = 0x00E0,
            SBM_SETSCROLLINFO = 0x00E9,
            EM_GETMODIFY = 0x00B8,
            EM_SETMODIFY = 0x00B9,
            WM_LBUTTONUP = 0x0202,
            WM_LBUTTONDOWN = 0x0201,
            WM_LBUTTONDBLCLK = 0x0203,
            WM_SYSTIMER = 0x0118,
            WM_SETFOCUS = 0x0007,
            WM_KILLFOCUS = 0x0008,
            WM_PAINT = 0x000F,
            WM_COMMAND = 0x0111,
            WM_CTLCOLORBTN = 0x0135,
            WM_CTLCOLORSCROLLBAR = 0x0137,
            WM_MDIACTIVATE = 0x222,
            WM_CAPTURECHANGED = 0x0215,
            CB_GETDROPPEDSTATE = 0x0157,
            WVR_VALIDRECTS = 0x400,
            WM_GETMINMAXINFO = 0x0024,
            WM_APPCOMMAND = 0x0319
        }
        public enum ComboNotificationCodes : int
        {
            CBN_DROPDOWN = 7,
            CBN_CLOSEUP = 8
        }
        public enum MouseKeyState : int
        {
            MK_LBUTTON = 0x0001,
            MK_RBUTTON = 0x0002,
            MK_SHIFT = 0x0004,
            MK_CONTROL = 0x0008,
            MK_MBUTTON = 0x0010,
            MK_XBUTTON1 = 0x0020,
            MK_XBUTTON2 = 0x0040
        }
        /// Options available when a form is tested for mose positions.
        public enum WindowHitTestRegions
        {
            /// HTERROR: On the screen background or on a dividing line between windows 
            /// (same as HTNOWHERE, except that the DefWindowProc function produces a system 
            /// beep to indicate an error).
            Error = -2,
            /// HTTRANSPARENT: In a window currently covered by another window in the 
            /// same thread (the message will be sent to underlying windows in the same thread 
            /// until one of them returns a code that is not HTTRANSPARENT).
            TransparentOrCovered = -1,
            /// HTNOWHERE: On the screen background or on a dividing line between 
            /// windows.
            NoWhere = 0,
            /// HTCLIENT: In a client area.
            ClientArea = 1,
            /// HTCAPTION: In a title bar.
            TitleBar = 2,
            /// HTSYSMENU: In a window menu or in a Close button in a child window.
            SystemMenu = 3,
            /// HTGROWBOX: In a size box (same as HTSIZE).
            GrowBox = 4,
            /// HTMENU: In a menu.
            Menu = 5,
            /// HTHSCROLL: In a horizontal scroll bar.
            HorizontalScrollBar = 6,
            /// HTVSCROLL: In the vertical scroll bar.
            VerticalScrollBar = 7,
            /// HTMINBUTTON: In a Minimize button. 
            MinimizeButton = 8,
            /// HTMAXBUTTON: In a Maximize button.
            MaximizeButton = 9,
            /// HTLEFT: In the left border of a resizable window (the user can click 
            /// the mouse to resize the window horizontally).
            LeftSizeableBorder = 10,
            /// HTRIGHT: In the right border of a resizable window (the user can click 
            /// the mouse to resize the window horizontally).
            RightSizeableBorder = 11,
            /// HTTOP: In the upper-horizontal border of a window.
            TopSizeableBorder = 12,
            /// HTTOPLEFT: In the upper-left corner of a window border.
            TopLeftSizeableCorner = 13,
            /// HTTOPRIGHT: In the upper-right corner of a window border.
            TopRightSizeableCorner = 14,
            /// HTBOTTOM: In the lower-horizontal border of a resizable window (the 
            /// user can click the mouse to resize the window vertically).
            BottomSizeableBorder = 15,
            /// HTBOTTOMLEFT: In the lower-left corner of a border of a resizable 
            /// window (the user can click the mouse to resize the window diagonally).
            BottomLeftSizeableCorner = 16,
            /// HTBOTTOMRIGHT: In the lower-right corner of a border of a resizable 
            /// window (the user can click the mouse to resize the window diagonally).
            BottomRightSizeableCorner = 17,
            /// HTBORDER: In the border of a window that does not have a sizing 
            /// border.
            NonSizableBorder = 18,
            /// HTOBJECT: Unknown...No Documentation Found
            Object = 19,
            /// HTCLOSE: In a Close button.
            CloseButton = 20,
            /// HTHELP: In a Help button.
            HelpButton = 21,
            /// HTSIZE: In a size box (same as HTGROWBOX). (Same as GrowBox).
            SizeBox = GrowBox,
            /// HTREDUCE: In a Minimize button. (Same as MinimizeButton).
            ReduceButton = MaximizeButton,
            /// HTZOOM: In a Maximize button. (Same as MaximizeButton).
            ZoomButton = MaximizeButton,
        }
        public enum GWL
        {
            GWL_WNDPROC = (-4),
            GWL_HINSTANCE = (-6),
            GWL_HWNDPARENT = (-8),
            GWL_STYLE = (-16),
            GWL_EXSTYLE = (-20),
            GWL_USERDATA = (-21),
            GWL_ID = (-12)
        }
        public enum RedrawWindowFlags : uint
        {
            RDW_INVALIDATE = 0x0001,
            RDW_INTERNALPAINT = 0x0002,
            RDW_ERASE = 0x0004,
            RDW_VALIDATE = 0x0008,
            RDW_NOINTERNALPAINT = 0x0010,
            RDW_NOERASE = 0x0020,
            RDW_NOCHILDREN = 0x0040,
            RDW_ALLCHILDREN = 0x0080,
            RDW_UPDATENOW = 0x0100,
            RDW_ERASENOW = 0x0200,
            RDW_FRAME = 0x0400,
            RDW_NOFRAME = 0x0800
        }
        [Flags()]
        public enum WindowStyles
        {
            WS_VISIBLE = 0x10000000,
            WS_CAPTION = 0x00C00000,
            WS_BORDER = 0x800000,
            WS_DLGFRAME = 0x400000,
            WS_THICKFRAME = 0x00040000
        }
        #endregion
        #region Windows API
        [DllImport("user32")]
        public static extern IntPtr WindowFromPoint(POINT p);
        [DllImport("user32.dll")]
        public static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern short GetKeyState(int keyCode);
        [DllImport("user32.dll")]
        public static extern bool IsZoomed(IntPtr hWnd);
        //[DllImport("user32.dll")]
        //public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
        [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
        [System.Runtime.InteropServices.DllImport("User32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
        [DllImport("gdi32.dll")]
        public static extern int ExcludeClipRect(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
        [DllImport("user32")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern bool GetTextMetrics(HandleRef hdc, TEXTMETRIC tm);
        [DllImport("user32.dll")]
        public static extern bool SetMenu(IntPtr hWnd, IntPtr hMenu);
        [DllImport("user32.dll")]
        public static extern IntPtr GetMenu(IntPtr hWnd);
        [DllImport("user32")]
        public static extern bool RedrawWindow(IntPtr hWnd, [In] ref RECT lprcUpdate, IntPtr hrgnUpdate, RedrawWindowFlags flags);
        [DllImport("user32")]
        public static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, RedrawWindowFlags flags);
        [DllImport("user32")]
        public static extern bool GetWindowRect(IntPtr hWnd, ref RECT r);
        [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetScrollBarInfo")]
        public static extern int GetScrollBarInfo(IntPtr hWnd, uint idObject, ref SCROLLBARINFO psbi);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int SetScrollInfo(HandleRef hWnd, int fnBar, ref SCROLLINFO si, bool redraw);
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowDC(IntPtr hWnd);
        [DllImport("user32.dll")]
        public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        public static extern bool AdjustWindowRectEx(ref RECT lpRect, int dwStyle,
           bool bMenu, int dwExStyle);
        // This static method is required because legacy OSes do not support
        // GetWindowLongPtr 
        public static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
        {
            if (IntPtr.Size == 8)
                return GetWindowLongPtr64(hWnd, nIndex);
            else
                return new IntPtr(GetWindowLong32(hWnd, nIndex));
        }
        [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
        public static extern int GetWindowLong32(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
        public static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref POINT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
        [DllImport("user32")]
        public static extern bool PostMessage(int hWnd, int Msg, int wParam, int lParam);
        [DllImport("user32")]
        public static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern bool DeleteDC(IntPtr hDC);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr CreateDIBSection(IntPtr hdc, BITMAPINFO pbmi, uint iUsage, int ppvBits, IntPtr hSection, uint dwOffset);
        [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
        public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
        [DllImport("gdi32")]
        public static extern bool DeleteObject(IntPtr hObject);
        [DllImport("gdi32")]
        public static extern bool DeleteObject(int hObject);
        public delegate void TimerDelegate(IntPtr hWnd, IntPtr uMsg, IntPtr idEvent, int dwTime);
        [DllImport("user32.dll")]
        public static extern UIntPtr SetTimer(IntPtr hWnd, UIntPtr nIDEvent, uint uElapse, TimerDelegate lpTimerFunc);
        [DllImport("user32.dll")]
        public static extern bool KillTimer(IntPtr hWnd, UIntPtr uIDEvent);
        #endregion
        #region Structures
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public class TEXTMETRIC
        {
            public int tmHeight;
            public int tmAscent;
            public int tmDescent;
            public int tmInternalLeading;
            public int tmExternalLeading;
            public int tmAveCharWidth;
            public int tmMaxCharWidth;
            public int tmWeight;
            public int tmOverhang;
            public int tmDigitizedAspectX;
            public int tmDigitizedAspectY;
            public char tmFirstChar;
            public char tmLastChar;
            public char tmDefaultChar;
            public char tmBreakChar;
            public byte tmItalic;
            public byte tmUnderlined;
            public byte tmStruckOut;
            public byte tmPitchAndFamily;
            public byte tmCharSet;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct SCROLLBARINFO
        {
            public int cbSize;
            public RECT rcScrollBar;
            public int dxyLineButton;
            public int xyThumbTop;
            public int xyThumbBottom;
            public int reserved;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public int[] rgstate;
        }
        public enum eScrollBarDirection
        {
            SB_HORZ = 0,
            SB_VERT = 1
        }
        public enum eScrollInfoMask
        {
            SIF_RANGE = 0x1,
            SIF_PAGE = 0x2,
            SIF_POS = 0x4,
            SIF_DISABLENOSCROLL = 0x8,
            SIF_TRACKPOS = 0x10,
            SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct SCROLLINFO
        {
            public int cbSize;
            public int fMask;
            public int nMin;
            public int nMax;
            public int nPage;
            public int nPos;
            public int nTrackPos;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct POINT
        {
            public int x;
            public int y;
            public POINT(System.Drawing.Point p)
            {
                this.x = p.X;
                this.y = p.Y;
            }
            public POINT(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
            public override string ToString()
            {
                return string.Format("{0},{1}", x, y);
            }
        }
        public enum ShowWindowCommands : int
        {
            /// 
            /// Hides the window and activates another window.
            /// 
            Hide = 0,
            /// 
            /// Activates and displays a window. If the window is minimized or
            /// maximized, the system restores it to its original size and position.
            /// An application should specify this flag when displaying the window
            /// for the first time.
            /// 
            Normal = 1,
            /// 
            /// Activates the window and displays it as a minimized window.
            /// 
            ShowMinimized = 2,
            /// 
            /// Maximizes the specified window.
            /// 
            Maximize = 3, // is this the right value?
            /// 
            /// Activates the window and displays it as a maximized window.
            ///       
            ShowMaximized = 3,
            /// 
            /// Displays a window in its most recent size and position. This value
            /// is similar to , except
            /// the window is not actived.
            /// 
            ShowNoActivate = 4,
            /// 
            /// Activates the window and displays it in its current size and position.
            /// 
            Show = 5,
            /// 
            /// Minimizes the specified window and activates the next top-level
            /// window in the Z order.
            /// 
            Minimize = 6,
            /// 
            /// Displays the window as a minimized window. This value is similar to
            /// , except the
            /// window is not activated.
            /// 
            ShowMinNoActive = 7,
            /// 
            /// Displays the window in its current size and position. This value is
            /// similar to , except the
            /// window is not activated.
            /// 
            ShowNA = 8,
            /// 
            /// Activates and displays the window. If the window is minimized or
            /// maximized, the system restores it to its original size and position.
            /// An application should specify this flag when restoring a minimized window.
            /// 
            Restore = 9,
            /// 
            /// Sets the show state based on the SW_* value specified in the
            /// STARTUPINFO structure passed to the CreateProcess function by the
            /// program that started the application.
            /// 
            ShowDefault = 10,
            /// 
            ///  Windows 2000/XP: Minimizes a window, even if the thread
            /// that owns the window is not responding. This flag should only be
            /// used when minimizing windows from a different thread.
            /// 
            ForceMinimize = 11
        }
        public struct WINDOWPLACEMENT
        {
            public int length;
            public int flags;
            public int showCmd;
            public POINT ptMinPosition;
            public POINT ptMaxPosition;
            public RECT rcNormalPosition;
        }
        /// 
        /// Retrieves the show state and the restored, minimized, and maximized positions of the specified window.
        /// 
        /// 
        /// A handle to the window.
        /// 
        /// 
        /// A pointer to the WINDOWPLACEMENT structure that receives the show state and position information.
        /// 
        /// Before calling GetWindowPlacement, set the length member to sizeof(WINDOWPLACEMENT). GetWindowPlacement fails if lpwndpl-> length is not set correctly.
        /// 
        /// 
        /// 
        /// If the function succeeds, the return value is nonzero.
        /// 
        /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
        /// 
        /// 
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
        [StructLayout(LayoutKind.Sequential)]
        public struct NCCALCSIZE_PARAMS
        {
            public RECT rgrc0, rgrc1, rgrc2;
            public IntPtr lppos;
        }
        [StructLayout(LayoutKind.Sequential)]
        public struct WINDOWPOS
        {
            public IntPtr hwnd;
            public IntPtr hwndInsertAfter;
            public int x, y;
            public int cx, cy;
            public int flags;
            public override string ToString()
            {
                return string.Format("x={0}, y={1}, right={2}, bottom={3}", x, y, cx, cy);
            }
        }
        [Serializable, StructLayout(LayoutKind.Sequential)]
        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_)
            {
                Left = left_;
                Top = top_;
                Right = right_;
                Bottom = bottom_;
            }
            public RECT(Rectangle r)
            {
                Left = r.Left;
                Top = r.Top;
                Right = r.Right;
                Bottom = r.Bottom;
            }
            public int Height { get { return Bottom - Top; } }
            public int Width { get { return Right - Left; } }
            public Size Size { get { return new Size(Width, Height); } }
            public Point Location { get { return new Point(Left, Top); } }
            // Handy method for converting to a System.Drawing.Rectangle
            public Rectangle ToRectangle()
            { return Rectangle.FromLTRB(Left, Top, Right, Bottom); }
            public static RECT FromRectangle(Rectangle rectangle)
            {
                return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
            }
            public override int GetHashCode()
            {
                return Left ^ ((Top << 13) | (Top >> 0x13))
                  ^ ((Width << 0x1a) | (Width >> 6))
                  ^ ((Height << 7) | (Height >> 0x19));
            }
            #region Operator overloads
            public static implicit operator Rectangle(RECT rect)
            {
                return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
            }
            public static implicit operator RECT(Rectangle rect)
            {
                return new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
            }
            public override string ToString()
            {
                return "Left=" + this.Left + ", Top=" + this.Top + ", Right=" + this.Right + ", Bottom=" + this.Bottom;
            }
            #endregion
        }
        [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
        public struct PAINTSTRUCT
        {
            public IntPtr hdc;
            public int fErase;
            public WinApi.RECT rcPaint;
            public int fRestore;
            public int fIncUpdate;
            public int Reserved1;
            public int Reserved2;
            public int Reserved3;
            public int Reserved4;
            public int Reserved5;
            public int Reserved6;
            public int Reserved7;
            public int Reserved8;
        }
        [StructLayout(LayoutKind.Sequential)]
        public class BITMAPINFO
        {
            public int biSize = 0;
            public int biWidth = 0;
            public int biHeight = 0;
            public short biPlanes = 0;
            public short biBitCount = 0;
            public int biCompression = 0;
            public int biSizeImage = 0;
            public int biXPelsPerMeter = 0;
            public int biYPelsPerMeter = 0;
            public int biClrUsed = 0;
            public int biClrImportant = 0;
            public byte bmiColors_rgbBlue = 0;
            public byte bmiColors_rgbGreen = 0;
            public byte bmiColors_rgbRed = 0;
            public byte bmiColors_rgbReserved = 0;
        }
        public enum eObjectId : uint
        {
            OBJID_CLIENT = 0xFFFFFFFC,
            OBJID_VSCROLL = 0xFFFFFFFB,
            OBJID_HSCROLL = 0xFFFFFFFA
        }
        public enum eStateFlags
        {
            STATE_SYSTEM_INVISIBLE = 0x00008000,
            STATE_SYSTEM_OFFSCREEN = 0x00010000,
            STATE_SYSTEM_PRESSED = 0x00000008,
            STATE_SYSTEM_UNAVAILABLE = 0x00000001
        }
        #endregion
        #region Functions
        public enum AppCommands
        {
            APPCOMMAND_BROWSER_BACKWARD = 1,
            APPCOMMAND_BROWSER_FORWARD = 2
        }
        private static int FAPPCOMMAND_MASK = 0xF000;
        public static int GetAppCommandLParam(IntPtr lParam)
        {
            return HIWORD(lParam) & ~FAPPCOMMAND_MASK;
        }
        public static int LOWORD(int n)
        {
            return (short)(n & 0xffff);
        }
        public static int HIWORD(int n)
        {
            return (int)((n >> 0x10) & 0xffff);
        }
        public static int LOWORD(IntPtr n)
        {
            return LOWORD((int)((long)n));
        }
        public static int HIWORD(IntPtr n)
        {
            return HIWORD((int)((long)n));
        }
        public static IntPtr CreateLParam(int loWord, int hiWord)
        {
            byte[] bx = BitConverter.GetBytes(loWord);
            byte[] by = BitConverter.GetBytes(hiWord);
            byte[] blp = new byte[] { bx[0], bx[1], by[0], by[1] };
            return new IntPtr(BitConverter.ToInt32(blp, 0));
        }
        #endregion
        #region DWM
        [StructLayout(LayoutKind.Sequential)]
        public struct MARGINS
        {
            public int cxLeftWidth;
            public int cxRightWidth;
            public int cyTopHeight;
            public int cyBottomHeight;
        }
        [DllImport("dwmapi.dll")]
        public static extern int DwmSetWindowAttribute(
           IntPtr hWnd,
           int dwAttribute,
           ref int attributeValue,
            int sizeOfValueRetrived
        );
        [DllImport("dwmapi.dll")]
        public static extern int DwmGetWindowAttribute(
            IntPtr hwnd,
            int dwAttribute,
            ref int pvAttribute,
            int sizeOfValueRetrived);
        [DllImport("dwmapi.dll", PreserveSig = false)]
        static extern bool DwmIsCompositionEnabled();
        [DllImport("dwmapi.dll")]
        public static extern int DwmDefWindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, out IntPtr plResult);
        [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "DefWindowProcW")]
        public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "DefWindowProcW")]
        public static extern IntPtr DefWindowProc(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
        [DllImport("dwmapi.dll")]
        public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
        public static void ExtendGlass(IntPtr handle, int glassHeight)
        {
            MARGINS margins = new MARGINS();
            margins.cxLeftWidth = 0;
            margins.cxRightWidth = 0;
            margins.cyTopHeight = glassHeight;
            margins.cyBottomHeight = 0;
            int result = DwmExtendFrameIntoClientArea(handle, ref margins);
        }
        public static bool IsGlassEnabled
        {
            get
            {
                if (System.Environment.OSVersion.Version.Major < 6)
                    return false;
                return DwmIsCompositionEnabled();
            }
        }
        public enum DWMWINDOWATTRIBUTE : int
        {
            DWMWA_NCRENDERING_ENABLED = 1,
            DWMWA_NCRENDERING_POLICY = 2,
            DWMWA_TRANSITIONS_FORCEDISABLED = 3,
            DWMWA_ALLOW_NCPAINT = 4,
            DWMWA_LAST = 5
        }
        public enum DWMNCRENDERINGPOLICY : int
        {
            DWMNCRP_USEWINDOWSTYLE = 0,
            DWMNCRP_DISABLED = 1,
            DWMNCRP_ENABLED = 2,
            DWMNCRP_LAST = 3
        }
        public enum WVR
        {
            ALIGNTOP = 0x0010,
            ALIGNLEFT = 0x0020,
            ALIGNBOTTOM = 0x0040,
            ALIGNRIGHT = 0x0080,
            HREDRAW = 0x0100,
            VREDRAW = 0x0200,
            VALIDRECTS = 0x0400,
            REDRAW = HREDRAW | VREDRAW,
        }
        #endregion
    }
}