public void extendFrame(int top, int bottom, int left, int right, Window window) { try { //set the form background to transparent window.Background = Brushes.Transparent; // 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 the system dpi values System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DpiX = desktop.DpiX; float pDpiY = desktop.DpiY; // Set Margins Margins margins = new Margins(); margins.Left = Convert.ToInt32((left + 5) * (DpiX / 96)); margins.Right = Convert.ToInt32((right + 5) * (DpiX / 96)); margins.Top = Convert.ToInt32((top + 5) * (DpiX / 96)); margins.Bottom = Convert.ToInt32((bottom + 5) * (DpiX / 96)); int check = GlassApi.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); if (check < 0) { //Cannot extend frame so set background to default window.Background = defaultColor; } } // If aero is not supported paint the background default catch (DllNotFoundException) { window.Background = defaultColor; } }
internal static extern int DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
public void extendFrame(int top, int bottom, int left, int right,Window window) { try { //set the form background to transparent window.Background = Brushes.Transparent; // 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 the system dpi values System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DpiX = desktop.DpiX; float pDpiY = desktop.DpiY; // Set Margins Margins margins = new Margins(); margins.Left = Convert.ToInt32((left + 5) * (DpiX / 96)); margins.Right = Convert.ToInt32((right + 5) * (DpiX / 96)); margins.Top = Convert.ToInt32((top + 5) * (DpiX / 96)); margins.Bottom = Convert.ToInt32((bottom + 5) * (DpiX / 96)); int check = GlassApi.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); if (check < 0) { //Cannot extend frame so set background to default window.Background = defaultColor; } } // If aero is not supported paint the background default catch (DllNotFoundException) { window.Background = defaultColor; } }
public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref Margins pMarInset);