예제 #1
0
        void OnGlass()
        {
            PresentationSource p            = PresentationSource.FromVisual(this);
            HwndSource         s_hwndSource = p as HwndSource;

            if (s_hwndSource != null)
            {
                s_hwndSource.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
                handle = s_hwndSource.Handle;
            }


            NativeMethods.RECT r = new NativeMethods.RECT();

            UnsafeNativeMethods.GetClientRect(handle, ref r);

            IntPtr hrgn = UnsafeNativeMethods.CreateRectRgn(0, 0, 1, 1);

            NativeMethods.DWM_BLURBEHIND bb = new NativeMethods.DWM_BLURBEHIND();
            bb.dwFlags  = NativeMethods.DWM_BB_ENABLE | NativeMethods.DWM_BB_BLURREGION;
            bb.fEnable  = true;
            bb.hRgnBlur = hrgn;

            UnsafeNativeMethods.DwmEnableBlurBehindWindow(handle, ref bb);

            NativeMethods.MARGINS mar = new NativeMethods.MARGINS();

            mar.cyTopHeight = 37;

            UnsafeNativeMethods.DwmExtendFrameIntoClientArea(handle, ref mar);

            //Need to make the Window size dirty.
            this.WindowState = WindowState.Minimized;
            this.WindowState = WindowState.Normal;
        }
예제 #2
0
        internal void UnapplyAeroStyle()
        {
            if (!DWMAPI.IsCompositionEnabled || this.IsDesignMode || this.parentForm == null)
            {
                return;
            }

            RadForm radForm = this.parentForm as RadForm;

            if (radForm != null)
            {
                radForm.AllowTheming = true;
                radForm.RootElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local);
            }

            IntPtr hwnd = this.parentForm.Handle;

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS();
            margins.cxLeftWidth    = 0;
            margins.cxRightWidth   = 0;
            margins.cyTopHeight    = 0;
            margins.cyBottomHeight = 0;
            DWMAPI.DwmExtendFrameIntoClientArea(hwnd, ref margins);

            this.parentForm.Refresh();
        }
예제 #3
0
        private void DrawBackground(Graphics g)
        {
            NativeMethods.MARGINS margins = default;
            _ = NativeMethods.DwmExtendFrameIntoClientArea(this.Handle, ref margins);

            // hopefully this is correct.
            var boarderRect = new Rectangle(0, 0, margins.rightWidth, margins.bottomHeight);

            if (boarderRect.Width > 0 && boarderRect.Height > 0)
            {
                // var color1 = Color.FromArgb(80, 80, 80);
                // var color2 = Color.FromArgb(40, 40, 40);
                // if (this.TransparentBackground)
                // {
                //     color1 = Color.Transparent;
                //     color2 = Color.Transparent;
                // }

                // using (var brush = new LinearGradientBrush(fillRect, color1, color2, LinearGradientMode.Vertical))
                // {
                using (var pen1 = new Pen(ShareXResources.Theme.BorderColor))
                {
                    g.DrawRectangle(pen1, boarderRect);
                }

                // }
            }

            // this.DrawText(g);
        }
예제 #4
0
        public void SetGlassMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin)
        {
            this.glassMargins = default(NativeMethods.MARGINS);

            this.glassMargins.cxLeftWidth = leftMargin;
            this.glassMargins.cxRightWidth = rightMargin;
            this.glassMargins.cyTopHeight = topMargin;
            this.glassMargins.cyButtomheight = bottomMargin;

            this.glassSet = true;
            this.ExtendFrameIntoClientArea();
        }
예제 #5
0
        private void ExtendFrameIntoClientArea()
        {
            if (!this.Form.IsHandleCreated)
            {
                return;
            }

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS();

            margins.cyTopHeight = this.TopCompositionMargin;
            DwmExtendFrameIntoClientArea(this.Form.Handle, ref margins);
        }
예제 #6
0
 public static void UnextendGlassFrame(this Window window)
 {
     if (!DwmAvaliable || !NativeMethods.DwmIsCompositionEnabled())
         return;
     IntPtr hwnd = new WindowInteropHelper(window).Handle;
     if (hwnd == IntPtr.Zero)
     {
         return;
     }
     NativeMethods.MARGINS margins = new NativeMethods.MARGINS(new Thickness(0));
     NativeMethods.DwmExtendFrameIntoClientArea(hwnd, ref margins);
     HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = (System.Windows.Media.Color)(Application.Current.TryFindResource("WindowBackgroundColor") ?? System.Windows.Media.Colors.White);
 }
        /// <summary>
        ///     Extend aero frame into the client area of the form by specified amounts.
        /// </summary>
        /// <param name="f">Form to extend into</param>
        /// <param name="insetMargins">Amount of pixels to extend inwards</param>
        /// <returns>True if operation succeeded, otherwise false.</returns>
        public static bool ExtendAeroFrameInwards(this Form f, Padding insetMargins)
        {
            var margins = new NativeMethods.MARGINS
            {
                cxLeftWidth    = insetMargins.Left,
                cxRightWidth   = insetMargins.Right,
                cyTopHeight    = insetMargins.Top,
                cyBottomHeight = insetMargins.Bottom
            };

            var result = NativeMethods.DwmExtendFrameIntoClientArea(f.Handle, ref margins);

            return(result == 0);
        }
예제 #8
0
 public static bool ExtendGlassFrame(this Window window, Thickness margin)
 {
     if (!DwmAvaliable || !NativeMethods.DwmIsCompositionEnabled())
         return false;
     IntPtr hwnd = new WindowInteropHelper(window).Handle;
     if (hwnd == IntPtr.Zero)
     {
         return false;
     }
     window.Background = System.Windows.Media.Brushes.Transparent;
     HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = System.Windows.Media.Colors.Transparent;
     NativeMethods.MARGINS margins = new NativeMethods.MARGINS(margin);
     NativeMethods.DwmExtendFrameIntoClientArea(hwnd, ref margins);
     return true;
 }
        private static void DeinitializeGlass(IntPtr hwnd)
        {
            // fill the background with glass
            var margins = new NativeMethods.MARGINS();

            margins.cxLeftWidth = margins.cxRightWidth = margins.cyBottomHeight = margins.cyTopHeight = -1;
            NativeMethods.DwmExtendFrameIntoClientArea(hwnd, ref margins);

            // initialize blur for the window
            var bbh = new NativeMethods.DWM_BLURBEHIND
            {
                fEnable = false,
                dwFlags = NativeMethods.DWM_BB.DWM_BB_ENABLE
            };

            NativeMethods.DwmEnableBlurBehindWindow(hwnd, ref bbh);
        }
예제 #10
0
        private void DrawBackground(Graphics g)
        {
            NativeMethods.MARGINS margins = default;
            _ = NativeMethods.DwmExtendFrameIntoClientArea(this.Handle, ref margins);

            // hopefully this is correct.
            var boarderRect = new Rectangle(0, 0, margins.rightWidth, margins.bottomHeight);

            if (boarderRect.Width > 0 && boarderRect.Height > 0)
            {
                using var pen1 = new Pen(ShareXResources.Theme.BorderColor);
                g.DrawRectangle(pen1, boarderRect);
            }

#if NEVER_DEFINED
            this.DrawText(g);
#endif
        }
예제 #11
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);
        }
예제 #12
0
        private void SetGlassOn()
        {
            if (IsGlassAvailable)
            {
                IntPtr     hwnd = new WindowInteropHelper(this).Handle;
                HwndSource src  = HwndSource.FromHwnd(hwnd);

                // settings the following value is necassary to have a transparent glass background instead of black:
                src.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);

                const int GlassBorderSize        = 8;
                const int GlassTitleBorderHeight = 31;

                NativeMethods.MARGINS margins = new NativeMethods.MARGINS();
                margins.cxLeftWidth    = GlassBorderSize;
                margins.cxRightWidth   = GlassBorderSize;
                margins.cyTopHeight    = GlassTitleBorderHeight;
                margins.cyBottomHeight = GlassBorderSize;
                NativeMethods.DwmExtendFrameIntoClientArea(hwnd, ref margins);
            }
        }
예제 #13
0
        /// <summary>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </summary>
        public Padding GetMargins(IDeviceContext dc, MarginProperty prop)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            //valid values are 0xe11 to 0xe13
            if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)MarginProperty.SizingMargins, (int)MarginProperty.CaptionMargins))
            {
                throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(MarginProperty));
            }

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS();

            using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) {
                HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc);
                lastHResult = SafeNativeMethods.GetThemeMargins(new HandleRef(this, Handle), hdc, part, state, (int)prop, prc: null, ref margins);
            }

            return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
        }
예제 #14
0
		/// <summary>
		/// Extends the glass effect into the form.
		/// </summary>
		/// <param name="form">The form where the glass is applied.</param>
		/// <param name="margin">The margin of the glass. Here the glass on each side of the form is specified. A margin with -1 creates the glass for all the form.</param>
		/// <param name="transparencyKey">This key must match the controls on the from that should host the glass effect.</param>
		public static bool ExtendGlass(Form form, Padding margin, Color transparencyKey)
		{
			if (form == null)
				throw new ArgumentNullException("form");

			if (!IsGlassEnabled)
				return false;

			// Backup the current transparency key.
			Color backup = form.TransparencyKey;

			// Set the transparency key of the form.
			form.TransparencyKey = transparencyKey;

			NativeMethods.MARGINS margins = new NativeMethods.MARGINS(margin);
			NativeMethods.DwmExtendFrameIntoClientArea(form.Handle, ref margins);

			// Set the backup back.
			form.TransparencyKey = backup;
			
			return true;
		}
예제 #15
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);
        }
예제 #16
0
        internal void ApplyAeroStyle()
        {
            if (!DWMAPI.IsCompositionEnabled || this.IsDesignMode || this.parentForm == null)
            {
                return;
            }

            RadForm radForm = this.parentForm as RadForm;

            if (radForm != null)
            {
                radForm.AllowTheming          = false;
                radForm.RootElement.BackColor = Color.Transparent;
            }
            else
            {
                this.parentForm.BackColor = Color.Black;
            }
            this.RootElement.BackColor = Color.Transparent;

            IntPtr hwnd = this.parentForm.Handle;

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS();
            margins.cxLeftWidth  = 0;
            margins.cxRightWidth = 0;
            if (this.Dock != DockStyle.Fill || this.Pages.Count == 0)
            {
                margins.cyTopHeight = this.parentForm.Size.Height;
            }
            else
            {
                margins.cyTopHeight = this.PageHeaderElement.Size.Height;
            }
            margins.cyBottomHeight = 0;
            DWMAPI.DwmExtendFrameIntoClientArea(hwnd, ref margins);

            this.parentForm.Refresh();
        }
예제 #17
0
        protected override void WndProc(ref Message m)
        {
            switch ((NativeMethods.WindowsMessages)m.Msg)
            {
            case NativeMethods.WindowsMessages.WM_NCPAINT:
                if (aeroShadow)
                {
                    var ncAttr     = NativeMethods.DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY;
                    var dwAttrPntr = 2;
                    NativeMethods.DwmSetWindowAttribute(Handle, ncAttr, ref dwAttrPntr, 4);

                    var margins = new NativeMethods.MARGINS()
                    {
                        cyBottomHeight = 1,
                        cxLeftWidth    = 1,
                        cxRightWidth   = 1,
                        cyTopHeight    = 1
                    };

                    NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margins);
                }
                break;

            case NativeMethods.WindowsMessages.WM_NCACTIVATE:
                // Change the title bar text color according to whether the
                // window is active or inactive
                if (m.WParam == IntPtr.Zero)
                {
                    XR_Container.TitleBarTextColor = Color.DarkGray;
                }
                else
                {
                    XR_Container.TitleBarTextColor = Color.Gainsboro;
                }
                break;
            }
            base.WndProc(ref m);
        }
예제 #18
0
 public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, [In] ref NativeMethods.MARGINS pMargins);
예제 #19
0
        /// <summary>
        /// Updates the display (position and appearance) of the window.
        /// </summary>
        /// <param name="activatewindow">True if the window should be activated, false if not.</param>
        public void UpdateWindowDisplay(bool activatewindow)
        {
            if (this.IsLoaded)
            {

                System.Windows.Data.CollectionViewSource wherelessViewModelViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("wherelessViewModelViewSource")));

                // set handlers if necessary
                this.SetHandlers();

                // get the handle of the window
                HwndSource windowhandlesource = PresentationSource.FromVisual(this) as HwndSource;

                bool glassenabled = Compatibility.IsDWMEnabled;

                //// update location

                Rect windowbounds = (glassenabled ? WindowPositioning.GetWindowSize(windowhandlesource.Handle) : WindowPositioning.GetWindowClientAreaSize(windowhandlesource.Handle));

                // work out the current screen's DPI
                Matrix screenmatrix = windowhandlesource.CompositionTarget.TransformToDevice;

                double dpiX = screenmatrix.M11; // 1.0 = 96 dpi
                double dpiY = screenmatrix.M22; // 1.25 = 120 dpi, etc.

                Point position = WindowPositioning.GetWindowPosition(this.NotifyIcon, windowbounds.Width, windowbounds.Height, dpiX, this.Pinned);

                // translate wpf points to screen coordinates
                Point screenposition = new Point(position.X / dpiX, position.Y / dpiY);

                this.Left = screenposition.X;
                this.Top = screenposition.Y;

                // update borders
                if (glassenabled)
                    this.Style = (Style)FindResource("AeroBorderStyle");
                else
                    this.SetNonGlassBorder(this.IsActive);

                // fix aero border if necessary
                if (glassenabled)
                {
                    // set the root border element's margin to 1 pixel
                    WindowBorder.Margin = new Thickness(1 / dpiX);
                    this.BorderThickness = new Thickness(0);

                    // set the background of the window to transparent (otherwise the inner border colour won't be visible)
                    windowhandlesource.CompositionTarget.BackgroundColor = Colors.Transparent;

                    // get dpi-dependent aero border width
                    int xmargin = Convert.ToInt32(1); // 1 unit wide
                    int ymargin = Convert.ToInt32(1); // 1 unit tall

                    NativeMethods.MARGINS margins = new NativeMethods.MARGINS() { cxLeftWidth = xmargin, cxRightWidth = xmargin, cyBottomHeight = ymargin, cyTopHeight = ymargin };

                    NativeMethods.DwmExtendFrameIntoClientArea(windowhandlesource.Handle, ref margins);
                }
                else
                {
                    WindowBorder.Margin = new Thickness(0); // reset the margin if the DWM is disabled
                    this.BorderThickness = new Thickness(1 / dpiX); // set the window's border thickness to 1 pixel
                }

                if (activatewindow)
                {
                    this.Show();
                    this.Activate();
                }
            }
        }
        /// <summary>
        /// Updates the display (position and appearance) of the window.
        /// </summary>
        /// <param name="activatewindow">True if the window should be activated, false if not.</param>
        public void UpdateWindowDisplay(bool activatewindow)
        {
            if (this.IsLoaded)
            {
                // set handlers if necessary
                this.SetHandlers();

                // get the handle of the window
                HwndSource windowhandlesource = PresentationSource.FromVisual(this) as HwndSource;

                bool glassenabled = Compatibility.IsDWMEnabled;

                //// update location

                Rect windowbounds = (glassenabled ? WindowPositioning.GetWindowSize(windowhandlesource.Handle) : WindowPositioning.GetWindowClientAreaSize(windowhandlesource.Handle));

                // work out the current screen's DPI
                Matrix screenmatrix = windowhandlesource.CompositionTarget.TransformToDevice;

                double dpiX = screenmatrix.M11; // 1.0 = 96 dpi
                double dpiY = screenmatrix.M22; // 1.25 = 120 dpi, etc.

                Point position = WindowPositioning.GetWindowPosition(this.NotifyIcon, windowbounds.Width, windowbounds.Height, dpiX);

                // translate wpf points to screen coordinates
                Point screenposition = new Point(position.X / dpiX, position.Y / dpiY);

                this.Left = screenposition.X;
                this.Top  = screenposition.Y;

                // update borders
                if (glassenabled)
                {
                    this.Style = (Style)FindResource("AeroBorderStyle");
                }
                else
                {
                    this.SetNonGlassBorder(this.IsActive);
                }

                // fix aero border if necessary
                if (glassenabled)
                {
                    // set the root border element's margin to 1 pixel
                    WindowBorder.Margin  = new Thickness(1 / dpiX);
                    this.BorderThickness = new Thickness(0);

                    // set the background of the window to transparent (otherwise the inner border colour won't be visible)
                    windowhandlesource.CompositionTarget.BackgroundColor = Colors.Transparent;

                    // get dpi-dependent aero border width
                    int xmargin = Convert.ToInt32(1); // 1 unit wide
                    int ymargin = Convert.ToInt32(1); // 1 unit tall

                    NativeMethods.MARGINS margins = new NativeMethods.MARGINS()
                    {
                        cxLeftWidth = xmargin, cxRightWidth = xmargin, cyBottomHeight = ymargin, cyTopHeight = ymargin
                    };

                    NativeMethods.DwmExtendFrameIntoClientArea(windowhandlesource.Handle, ref margins);
                }
                else
                {
                    WindowBorder.Margin  = new Thickness(0);        // reset the margin if the DWM is disabled
                    this.BorderThickness = new Thickness(1 / dpiX); // set the window's border thickness to 1 pixel
                }

                if (activatewindow)
                {
                    this.Show();
                    this.Activate();
                }
            }
        }
예제 #21
0
        public static void ExtendFrameIntoClientArea(IWin32Window window, int left, int top, int right, int bottom)
        {
            var margins = new NativeMethods.MARGINS(left, top, right, bottom);

            UnsafeNativeMethods.DwmExtendFrameIntoClientArea(window.Handle, ref margins);
        }
        /// <summary>
        /// When the form is painted, set the region where the glass effect
        /// is applied.
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if ((!ExtendFrameEnabled && !BlurBehindWindowEnabled) ||
                !IsAeroGlassStyleSupported())
            {
                return;
            }

            using (Brush transparentBrush = new SolidBrush(transparentColor))
            {
                // Extend the frame.
                if (ExtendFrameEnabled)
                {
                    var glassMargins = this.GlassMargins;

                    // Extend the frame.
                    NativeMethods.DwmExtendFrameIntoClientArea(this.Handle,
                                                               ref glassMargins);

                    // Make the region in the margins transparent.
                    marginRegion = new Region(this.ClientRectangle);

                    // If the glassMargins contains a negative value, or the values are not valid,
                    // then make the whole form transparent.
                    if (this.GlassMargins.IsNegativeOrOverride(this.ClientSize))
                    {
                        e.Graphics.FillRegion(transparentBrush, marginRegion);
                    }

                    // By default, exclude the region of the client area.
                    else
                    {
                        marginRegion.Exclude(new Rectangle(
                                                 this.GlassMargins.cxLeftWidth,
                                                 this.GlassMargins.cyTopHeight,
                                                 this.ClientSize.Width - this.GlassMargins.cxLeftWidth -
                                                 this.GlassMargins.cxRightWidth,
                                                 this.ClientSize.Height - this.GlassMargins.cyTopHeight -
                                                 this.GlassMargins.cyBottomHeight));
                        e.Graphics.FillRegion(transparentBrush, marginRegion);
                    }
                }

                // Reset the frame to the default state.
                else
                {
                    var glassMargins = new NativeMethods.MARGINS(-1);
                    NativeMethods.DwmExtendFrameIntoClientArea(this.Handle,
                                                               ref glassMargins);
                }

                // Enable the blur effect on the form.
                if (BlurBehindWindowEnabled)
                {
                    ResetDwmBlurBehind(true, e.Graphics);

                    if (this.BlurRegion != null)
                    {
                        e.Graphics.FillRegion(transparentBrush, BlurRegion);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(transparentBrush, this.ClientRectangle);
                    }
                }
                else
                {
                    ResetDwmBlurBehind(false, null);
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Extends the glass window frame into the client area of the specified window.
        /// </summary>
        /// <param name="window">The <see cref="IWin32Window"/> on which to enable client area glass.</param>
        /// <param name="glassMargin">The the margins to use when extending the frame into the client area.</param>
        /// <remarks>
        /// <para>
        ///   Use negative margins to create the "sheet of glass" effect where the client area is rendered 
        ///   as a completely glass surface.
        /// </para>
        /// <para>
        ///   The glass area must be filled with either a black brush or the <see cref="Form.TransparencyKey" /> color
        ///   in order to display correctly. If the <see cref="Form.TransparencyKey"/> method is used, clicks in the
        ///   glass area will "fall through" the window to the window below it. If the black brush method is used, text
        ///   rendered with the <see cref="TextRenderer" /> will not display correctly on the glass area (this includes
        ///   text drawn by most controls). To draw text on the glass area, use <see cref="DrawCompositedText"/>.
        /// </para>
        /// <para>
        ///   This method needs to be called again if the state of the Desktop Window Manager is toggled.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="window"/> is <see langword="null" />.</exception>
        /// <exception cref="NotSupportedException">The current operating system does not support glass, or the Desktop Window Manager is not enabled.</exception>
        public static void ExtendFrameIntoClientArea(this System.Windows.Forms.IWin32Window window, Padding glassMargin)
        {
            if( !IsDwmCompositionEnabled )
                throw new NotSupportedException(Properties.Resources.GlassNotSupportedError);

            if( window == null )
                throw new ArgumentNullException("window");

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS(glassMargin);
            NativeMethods.DwmExtendFrameIntoClientArea(window.Handle, ref margins);
        }
예제 #24
0
        public static void ExtendFrameIntoClientArea(IWin32Window window)
        {
            var margins = new NativeMethods.MARGINS(-1);

            UnsafeNativeMethods.DwmExtendFrameIntoClientArea(window.Handle, ref margins);
        }
예제 #25
0
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                if (NativeMethods.DwmIsCompositionEnabled())
                {
                    NativeMethods.MARGINS m = new NativeMethods.MARGINS(0, 0, 0, 0);
                    NativeMethods.DwmExtendFrameIntoClientArea(this.Handle, m);
                }
            }
            catch (Exception)
            {
                //NOTE: if it fails, it fails - its probably Windows XP
            }

            base.OnLoad(e);
        }
예제 #26
0
 internal static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref NativeMethods.MARGINS margins);
예제 #27
0
        void ExtendFrameIntoClientArea(IntPtr handle)
        {
            var margin = new NativeMethods.MARGINS(1);

            UnsafeNativeMethods.DwmExtendFrameIntoClientArea(handle, ref margin);
        }
예제 #28
0
 public static extern int GetThemeMargins(HandleRef hTheme, HandleRef hDC, int iPartId, int iStateId, int iPropId, NativeMethods.COMRECT prc, ref NativeMethods.MARGINS margins);
예제 #29
0
        protected override void WndProc(ref Message m)
        {
            if (aeroEnabled)
            {
                switch (m.Msg)
                {
                case NativeMethods.WM_SYSCOMMAND:
                    if (m.WParam.ToInt32() == 0xF120)
                    {
                        Console.WriteLine("!!");
                        m.Result = new IntPtr(1);
                    }

                    if (m.WParam.ToInt32() == 0xF020)
                    {
                        Console.WriteLine("!!2");
                        m.Result = new IntPtr(1);
                    }
                    break;

                case NativeMethods.WM_GETMINMAXINFO:
                    WmGetMinMaxInfo(ref m);
                    break;

                case NativeMethods.WM_NCPAINT:
                    var attrValue = 2;

                    var margins = new NativeMethods.MARGINS()
                    {
                        cyBottomHeight = 1,
                        cxLeftWidth    = 1,
                        cxRightWidth   = 1,
                        cyTopHeight    = 1
                    };

                    UnsafeNativeMethods.DwmSetWindowAttribute(this.Handle, 2, ref attrValue, 4);
                    UnsafeNativeMethods.DwmExtendFrameIntoClientArea(this.Handle, ref margins);
                    break;

                case NativeMethods.WM_NCCALCSIZE:
                    if (m.WParam.ToInt32() == 1)
                    {
                        m.Result = new IntPtr(0xF0);
                        return;
                    }
                    break;
                }
            }

            base.WndProc(ref m);

            if (m.Msg == NativeMethods.WM_NCHITTEST && (int)m.Result == NativeMethods.HTCLIENT)
            {
                var pos = MousePosition - (Size)this.Location;

                foreach (var bound in hitVisibles.Values)
                {
                    if (bound.Contains(pos))
                    {
                        return;
                    }
                }

                m.Result = (IntPtr)NativeMethods.HTCAPTION;
            }
        }