Beispiel #1
0
        public static bool ExtendGlass(Window win, int left, int right, int top, int bottom)
        {
            try
            {
                if (!DwmIsCompositionEnabled())
                {
                    return(false);
                }
                // Obtain the window handle for WPF application
                WindowInteropHelper windowInterop = new WindowInteropHelper(win);
                IntPtr     windowHandle           = windowInterop.Handle;
                HwndSource mainWindowSrc          = HwndSource.FromHwnd(windowHandle);
                mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;

                VistaGlassHelper.Margins margins =
                    VistaGlassHelper.GetDpiAdjustedMargins(windowHandle, left, right, top, bottom);

                int returnVal = VistaGlassHelper.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);

                if (returnVal < 0)
                {
                    throw new NotSupportedException("Operation failed.");
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }