Exemplo n.º 1
0
        public static int ExtendFrameIntoClientArea(Window window, int leftWidth, int rightWidth, int topHeight, int bottomHeight)
        {
            try
            {
                // Get the window handle
                IntPtr     mainWindowPtr = new WindowInteropHelper(window).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get DPI
                using (var desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr))
                {
                    float DesktopDpiX = desktop.DpiX / 96;
                    float DesktopDpiY = desktop.DpiY / 96;

                    // Set Margins
                    DwmMargins margins = new DwmMargins();

                    margins.xLeft   = (int)(leftWidth * DesktopDpiX);
                    margins.xRight  = (int)(rightWidth * DesktopDpiX);
                    margins.yTop    = (int)(topHeight * DesktopDpiY);
                    margins.yBottom = (int)(bottomHeight * DesktopDpiY);

                    return(DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins));
                }
            }
            catch (DllNotFoundException)
            {
                return(-1);
            }
        }
Exemplo n.º 2
0
        public static int ExtendFrameIntoClientArea(Window window, int leftWidth, int rightWidth, int topHeight, int bottomHeight)
        {
            try
            {
                // Get the window handle
                IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                // Get DPI
                using (var desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr))
                {
                    float DesktopDpiX = desktop.DpiX / 96;
                    float DesktopDpiY = desktop.DpiY / 96;

                    // Set Margins
                    DwmMargins margins = new DwmMargins();

                    margins.xLeft = (int)(leftWidth * DesktopDpiX);
                    margins.xRight = (int)(rightWidth * DesktopDpiX);
                    margins.yTop = (int)(topHeight * DesktopDpiY);
                    margins.yBottom = (int)(bottomHeight * DesktopDpiY);

                    return DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
                }
            }
            catch (DllNotFoundException)
            {
                return -1;
            }
        }
Exemplo n.º 3
0
 private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref DwmMargins pMarInset);
Exemplo n.º 4
0
 private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref DwmMargins pMarInset);