Exemplo n.º 1
0
        /// <summary>
        /// Registers a thumbnail to be drawn on a window.
        /// </summary>
        /// <remarks>
        /// The thumbnail will not be drawn until you update the thumbnail's properties
        /// using <see cref="Thumbnail.Update"/>.
        /// </remarks>
        /// <param name="destination">The handle (Win32 HWND) of the window on which the thumbnail will be drawn.</param>
        /// <param name="source">The handle (Win32 HWND) of the window that has to be drawn.</param>
        /// <returns>A Thumbnail instance, needed to unregister and to update properties.</returns>
        public static Thumbnail Register(IntPtr destination, IntPtr source)
        {
            if (!OsSupport.IsVistaOrLater)
            {
                throw new DwmCompositionException(ExceptionMessages.DwmOsNotSupported);
            }

            if (!OsSupport.IsCompositionEnabled)
            {
                throw new DwmCompositionException(ExceptionMessages.DwmNotEnabled);
            }

            if (destination == source)
            {
                throw new DwmCompositionException(ExceptionMessages.DwmWindowMatch);
            }

            if (DwmMethods.DwmRegisterThumbnail(destination, source, out IntPtr ret) == 0)
            {
                return(new Thumbnail(ret));
            }
            else
            {
                throw new DwmCompositionException(string.Format(ExceptionMessages.NativeCallFailure, nameof(DwmMethods.DwmRegisterThumbnail)));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the thumbnail's display settings.
        /// </summary>
        /// <param name="destination">Drawing region on destination window.</param>
        /// <param name="source">Origin region from source window.</param>
        /// <param name="opacity">Opacity. 0 is transparent, 255 opaque.</param>
        /// <param name="visible">Visibility flag.</param>
        /// <param name="onlyClientArea">
        /// If true, only the client area of the window will be rendered. Otherwise, the
        /// borders will be be rendered as well.
        /// </param>
        public void Update(Rectangle destination, Rectangle source, byte opacity, bool visible, bool onlyClientArea)
        {
            if (source.Width < 1 || source.Height < 1)
            {
                throw new ArgumentException(ExceptionMessages.DwmThumbnailSourceInvalid);
            }

            var prop = new DwmThumbnailProperties {
                rcDestination         = new Rect(destination),
                rcSource              = new Rect(source),
                opacity               = opacity,
                fVisible              = visible,
                fSourceClientAreaOnly = onlyClientArea,
                dwFlags               = DwmThumbnailFlags.RectDestination |
                                        DwmThumbnailFlags.RectSource |
                                        DwmThumbnailFlags.Opacity |
                                        DwmThumbnailFlags.Visible |
                                        DwmThumbnailFlags.SourceClientAreaOnly
            };

            if (DwmMethods.DwmUpdateThumbnailProperties(handle, ref prop) != 0)
            {
                throw new DwmCompositionException(ExceptionMessages.DwmThumbnailUpdateFailure);
            }

            _destination = destination;
            _opacity     = opacity;
            _visible     = visible;
            _clientArea  = ShowOnlyClientArea;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets whether a window's DWM representation is frozen.
        /// </summary>
        /// <param name="hwnd">Handle of the window whose representation status must be returned.</param>
        /// <returns>Returns false on OSs that do not support frozen DWM representation.</returns>
        public static bool IsFrozen(IntPtr hwnd)
        {
            if (!OsSupport.IsEightOrLater)
            {
                return(false);
            }

            return(DwmMethods.DwmGetWindowFreezeRepresentation(hwnd));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets whether a window is cloaked.
        /// </summary>
        /// <remarks>Always returns <see cref="CloakedStatus.Uncloaked"/> on unsupported OSs.</remarks>
        public static CloakedStatus IsCloaked(IntPtr hwnd)
        {
            if (!OsSupport.IsEightOrLater)
            {
                return(CloakedStatus.Uncloaked);
            }

            return(DwmMethods.DwmGetWindowCloaked(hwnd));
        }
Exemplo n.º 5
0
        protected override bool ReleaseHandle()
        {
            if (handle == IntPtr.Zero)
            {
                return(true);
            }

            //Unregister the thumbnail
            return(DwmMethods.DwmUnregisterThumbnail(handle) == 0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves the thumbnailed window's size.
        /// </summary>
        public System.Drawing.Size GetSourceSize()
        {
            DwmSize size;

            if (DwmMethods.DwmQueryThumbnailSourceSize(handle, out size) != 0)
            {
                throw new DwmCompositionException(ExceptionMessages.DwmThumbnailQueryFailure);
            }

            return(size.ToSize());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sets whether a window's DWM representation is frozen.
        /// </summary>
        /// <param name="hwnd">Handle of the window whose representation status should be set.</param>
        /// <param name="freeze">True if the window's DWM representation should be frozen.</param>
        /// <remarks>Is ignored on OSs that do not support frozen DWM representation.</remarks>
        public static void SetFrozenRepresentation(IntPtr hwnd, bool freeze)
        {
            if (!OsSupport.IsEightOrLater)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowFreezeRepresentation(hwnd, freeze) != 0)
            {
                throw new Exception(ExceptionMessages.DwmFreezeRepresentationFail);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sets a window's cloak status.
        /// </summary>
        /// <remarks>Is ignored on OSs that do not support cloaking.</remarks>
        public static void SetCloak(IntPtr hwnd, bool cloak)
        {
            if (!OsSupport.IsEightOrLater)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowCloaked(hwnd, cloak) != 0)
            {
                throw new Exception(ExceptionMessages.DwmCloakFail);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Sets whether Aero Peek excludes or includes a window.
        /// </summary>
        /// <param name="form">Form whose Aero Peek exclusion state is to be set.</param>
        /// <param name="excluded">Set to true to exlude the window from Aero Peek.</param>
        /// <remarks>Is ignored on OSs that do not support Aero Peek.</remarks>
        public static void SetExcludeFromPeek(Form form, bool excluded)
        {
            if (!OsSupport.IsSevenOrLater || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowExcludedFromPeek(form.Handle, excluded) != 0)
            {
                throw new Exception(ExceptionMessages.DwmExcludePeekFail);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Sets whether Aero Peek is enabled or disabled on a window.
        /// </summary>
        /// <param name="hwnd">Handle of the window whose Aero Peek state should be altered.</param>
        /// <param name="disallowPeek">True if Aero Peek should be disabled for the window. False otherwise.</param>
        /// <remarks>Is ignored on OSs that do not support Aero Peek.</remarks>
        public static void SetDisallowPeek(IntPtr hwnd, bool disallowPeek)
        {
            if (!OsSupport.IsSevenOrLater || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowDisallowPeek(hwnd, disallowPeek) != 0)
            {
                throw new Exception(ExceptionMessages.DwmDisallowPeekFail);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sets whether Aero Peek is enabled or disabled on a window.
        /// </summary>
        /// <param name="form">Form whose Aero Peek state should be altered.</param>
        /// <param name="disallowPeek">True if Aero Peek should be disabled for the window. False otherwise.</param>
        /// <remarks>Is ignored on OSs that do not support Aero Peek.</remarks>
        public static void SetDisallowPeek(Form form, bool disallowPeek)
        {
            if (!OsSupport.IsSevenOrBetter || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowDisallowPeek(form.Handle, disallowPeek) != 0)
            {
                throw new Exception(ExceptionMessages.DwmDisallowPeekFail);
            }
        }
Exemplo n.º 12
0
        private static void InternalGlassFrame(IntPtr hWnd, Padding margins)
        {
            if (!OsSupport.IsVistaOrLater || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            var nativeMargins = Margins.FromPadding(margins);

            if (DwmMethods.DwmExtendFrameIntoClientArea(hWnd, ref nativeMargins) != 0)
            {
                throw new DwmCompositionException(string.Format(ExceptionMessages.NativeCallFailure, nameof(DwmMethods.DwmExtendFrameIntoClientArea)));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Disables the Aero "Blur Behind" effect.
        /// </summary>
        public static void DisableBlurBehind(IntPtr hWnd)
        {
            if (!OsSupport.IsVistaOrLater || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            var bb = new DwmBlurBehind {
                fEnable = false,
                dwFlags = DwmBlurBehindFlags.Enable
            };

            DwmMethods.DwmEnableBlurBehindWindow(hWnd, ref bb);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Enable the Aero "Blur Behind" effect on the whole client area.
        /// Background of the clint area must be painted in black.
        /// </summary>
        public static void EnableBlurBehind(IntPtr hWnd)
        {
            if (!OsSupport.IsVistaOrBetter || !OsSupport.IsCompositionEnabled)
            {
                return;
            }

            var bb = new DwmBlurBehind {
                fEnable  = true,
                hRgnBlur = IntPtr.Zero,
                dwFlags  = DwmBlurBehindFlags.Enable
            };

            DwmMethods.DwmEnableBlurBehindWindow(hWnd, ref bb);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Sets a window's Flip 3D policy.
        /// </summary>
        /// <param name="form">Form whose policy is to be set.</param>
        /// <param name="policy">Desired Flip 3D policy.</param>
        /// <remarks>Is ignored on OSs that do not support Aero.</remarks>
        public static void SetWindowFlip3dPolicy(Form form, Flip3DPolicy policy)
        {
            if (!OsSupport.IsVistaOrBetter || OsSupport.IsEightOrBetter)
            {
                return;
            }

            if (!OsSupport.IsCompositionEnabled)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowFlip3dPolicy(form.Handle, policy) != 0)
            {
                throw new Exception(ExceptionMessages.DwmFlip3dFailPolicy);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets a window's Flip 3D policy.
        /// </summary>
        /// <param name="hwnd">Handle of the window whose Flip 3D state should be altered.</param>
        /// <param name="policy">Desired Flip 3D policy.</param>
        /// <remarks>Is ignored on OSs that do not support Aero.</remarks>
        public static void SetWindowFlip3dPolicy(IntPtr hwnd, Flip3DPolicy policy)
        {
            // Works only on Vista
            if (!OsSupport.IsVistaOrLater || OsSupport.IsEightOrLater)
            {
                return;
            }

            if (!OsSupport.IsCompositionEnabled)
            {
                return;
            }

            if (DwmMethods.DwmSetWindowFlip3dPolicy(hwnd, policy) != 0)
            {
                throw new Exception(ExceptionMessages.DwmFlip3dFailPolicy);
            }
        }