Exemple #1
0
            public static Margins GetDpiAdjustedMargins(IntPtr windowHandle, int left, int right, int top, int bottom)
            {
                // Получить Dpi системы
                System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(windowHandle);
                float DesktopDpiX = desktop.DpiX;
                float DesktopDpiY = desktop.DpiY;

                // Установка полей
                AeroEffect.Win7.Margins margins = new AeroEffect.Win7.Margins();

                margins.cxLeftWidth    = Convert.ToInt32(left * (DesktopDpiX / 96));
                margins.cxRightWidth   = Convert.ToInt32(right * (DesktopDpiX / 96));
                margins.cyTopHeight    = Convert.ToInt32(top * (DesktopDpiX / 96));
                margins.cyBottomHeight = Convert.ToInt32(right * (DesktopDpiX / 96));

                return(margins);
            }
Exemple #2
0
            public static void EnableBlur(Window win, int left, int right, int top, int bottom)
            {
                // Получение Win32-дескриптора для окна WPF
                WindowInteropHelper windowInterop = new WindowInteropHelper(win);
                IntPtr     windowHandle           = windowInterop.Handle;
                HwndSource mainWindowSrc          = HwndSource.FromHwnd(windowHandle);

                mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;

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

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

                if (returnVal < 0)
                {
                    throw new NotSupportedException("Operation failed.");
                }
            }
Exemple #3
0
            public static void EnableBlur(Window win)
            {
                try {
                    // Obtain the window handle for WPF application
                    IntPtr     mainWindowPtr = new WindowInteropHelper(win).Handle;
                    HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                    mainWindowSrc.CompositionTarget.BackgroundColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);

                    // Get System Dpi
                    System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr);
                    float DesktopDpiX = desktop.DpiX;
                    float DesktopDpiY = desktop.DpiY;

                    // Set Margins
                    AeroEffect.Win7.Margins margins = new AeroEffect.Win7.Margins();

                    // Extend glass frame into client area
                    // Note that the default desktop Dpi is 96dpi. The  margins are
                    // adjusted for the system Dpi.
                    margins.cxLeftWidth    = -1; //   Convert.ToInt32(5 * (DesktopDpiX / 96));
                    margins.cxRightWidth   = -1; //  Convert.ToInt32(5 * (DesktopDpiX / 96));
                    margins.cyTopHeight    = -1; //   Convert.ToInt32(5 * (DesktopDpiX / 96));
                    margins.cyBottomHeight = -1; //Convert.ToInt32(5 * (DesktopDpiX / 96));

                    int hr = AeroEffect.Win7.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
                    //
                    if (hr < 0)
                    {
                        //DwmExtendFrameIntoClientArea Failed
                    }
                }
                // If not Vista, paint background white.
                catch (DllNotFoundException)
                {
                    Application.Current.MainWindow.Background = System.Windows.Media.Brushes.White;
                }
            }