Example #1
0
        private void GlassWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (DisableAeroGlass)
            {
                return;
            }
            Console.WriteLine("OS Version: " + Environment.OSVersion.Version.ToString());
            var handle = _windowInteropHelper.Handle;

            _mainWindowSrc = HwndSource.FromHwnd(handle);

            if (_mainWindowSrc == null || _mainWindowSrc.CompositionTarget == null)
            {
                MessageBox.Show("Error getting HwndSource! Window appearance can't be properly set!", "Exception in Loaded", MessageBoxButton.OK,
                                MessageBoxImage.Asterisk);
                return;
            }
            _mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;
            var glassParams = new NativeMethods.DwmBlurbehind
            {
                dwFlags     = NativeMethods.DwmBlurbehind.DWM_BB_ENABLE,
                fEnable     = true,
                hRegionBlur = IntPtr.Zero
            };

            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor < 2)
            {
                var dis = 2;
                NativeMethods.DwmSetWindowAttribute(_mainWindowSrc.Handle,
                                                    NativeMethods.DwmWindowAttribute.DWMWA_LAST,
                                                    ref dis,
                                                    sizeof(uint));
            }
            else if (Environment.OSVersion.Version.Major > 6)
            {
                var m = new NativeMethods.MARGINS();
                m.cxLeftWidth = m.cxRightWidth = m.cyBottomHeight = m.cyTopHeight = -1;
                NativeMethods.DwmExtendFrameIntoClientArea(handle, ref m);
            }

            NativeMethods.DwmEnableBlurBehindWindow(handle, glassParams);
        }
Example #2
0
        private void GlassWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (DisableAeroGlass) return;
            Console.WriteLine("OS Version: " + Environment.OSVersion.Version.ToString());
            var handle = _windowInteropHelper.Handle;
            _mainWindowSrc = HwndSource.FromHwnd(handle);

            if (_mainWindowSrc == null || _mainWindowSrc.CompositionTarget == null)
            {
                MessageBox.Show("Error getting HwndSource! Window appearance can't be properly set!", "Exception in Loaded", MessageBoxButton.OK,
                    MessageBoxImage.Asterisk);
                return;
            }
            _mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;
            var glassParams = new NativeMethods.DwmBlurbehind
            {
                dwFlags = NativeMethods.DwmBlurbehind.DWM_BB_ENABLE,
                fEnable = true,
                hRegionBlur = IntPtr.Zero
            };

            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor < 2)
            {
                var dis = 2;
                NativeMethods.DwmSetWindowAttribute(_mainWindowSrc.Handle,
                    NativeMethods.DwmWindowAttribute.DWMWA_LAST,
                    ref dis,
                    sizeof(uint));
            }
            else if (Environment.OSVersion.Version.Major > 6)
            {
                var m = new NativeMethods.MARGINS();
                m.cxLeftWidth = m.cxRightWidth = m.cyBottomHeight = m.cyTopHeight = -1;
                NativeMethods.DwmExtendFrameIntoClientArea(handle, ref m);
            }

            NativeMethods.DwmEnableBlurBehindWindow(handle, glassParams);
        }