diff --git a/WIndows.Forms/DesktopWindowManager.cs b/WIndows.Forms/DesktopWindowManager.cs index 1d0aae57..4ff34345 100644 --- a/WIndows.Forms/DesktopWindowManager.cs +++ b/WIndows.Forms/DesktopWindowManager.cs @@ -11,8 +11,8 @@ using static Vanara.PInvoke.DwmApi; namespace Vanara.Windows.Forms { /// Main DWM class, provides glass sheet effect and blur behind. - [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces")] - [global::System.Security.Permissions.PermissionSet(global::System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces")] + [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] [SecuritySafeCritical] public static partial class DesktopWindowManager { @@ -20,7 +20,6 @@ namespace Vanara.Windows.Forms private static readonly object _lock = new object(); private static readonly object colorizationColorChangedKey = new object(); private static readonly object compositionChangedKey = new object(); - //static object windowMaximizedChangedKey = new object(); private static readonly object[] keys = { compositionChangedKey, nonClientRenderingChangedKey, colorizationColorChangedKey/*, WindowMaximizedChangedKey*/ }; private static readonly object nonClientRenderingChangedKey = new object(); private static EventHandlerList eventHandlerList; @@ -47,8 +46,10 @@ namespace Vanara.Windows.Forms remove { RemoveEventHandler(nonClientRenderingChangedKey, value); } } - /// Use with GetWindowAttr and WindowAttribute.Cloaked. If the window is cloaked, provides one of the following values explaining why. - [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames")] + /// + /// Use with GetWindowAttr and WindowAttribute.Cloaked. If the window is cloaked, provides one of the following values explaining why. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames")] [Flags] public enum CloakingSource { @@ -65,7 +66,9 @@ namespace Vanara.Windows.Forms /// Flags used by the SetWindowAttr method to specify the Flip3D window policy. public enum Flip3DWindowPolicy { - /// Use the window's style and visibility settings to determine whether to hide or include the window in Flip3D rendering. + /// + /// Use the window's style and visibility settings to determine whether to hide or include the window in Flip3D rendering. + /// Default, /// Exclude the window from Flip3D and display it below the Flip3D rendering. @@ -89,8 +92,8 @@ namespace Vanara.Windows.Forms } /// - /// Gets or sets the current color used for Desktop Window Manager (DWM) glass composition. This value is based on the current color scheme and can be - /// modified by the user. + /// Gets or sets the current color used for Desktop Window Manager (DWM) glass composition. This value is based on the current color + /// scheme and can be modified by the user. /// /// The color of the glass composition. public static Color CompositionColor @@ -126,10 +129,12 @@ namespace Vanara.Windows.Forms public static bool CompositionSupported => Environment.OSVersion.Version.Major >= 6; /// - /// Gets a value notifying the Desktop Window Manager (DWM) to opt in to or out of Multimedia Class Schedule Service (MMCSS) scheduling while the calling - /// process is alive. + /// Gets a value notifying the Desktop Window Manager (DWM) to opt in to or out of Multimedia Class Schedule Service (MMCSS) + /// scheduling while the calling process is alive. /// - /// true to instruct DWM to participate in MMCSS scheduling; otherwise, false to opt out or end participation in MMCSS scheduling. + /// + /// true to instruct DWM to participate in MMCSS scheduling; otherwise, false to opt out or end participation in MMCSS scheduling. + /// public static bool MultimediaClassScheduleServiceEnabled { set => DwmEnableMMCSS(value).ThrowIfFailed(); } /// Gets or sets a value that indicates whether the is transparent. @@ -164,28 +169,31 @@ namespace Vanara.Windows.Forms /// Enables content rendered in the non-client area to be visible on the frame drawn by DWM. /// The form. - /// Set to true to enable content rendered in the non-client area to be visible on the frame; otherwise, false. - public static void AllowNonClientPainting(this Form form, bool allowNCPaint) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_ALLOW_NCPAINT, allowNCPaint); + /// + /// Set to true to enable content rendered in the non-client area to be visible on the frame; otherwise, false. + /// + public static void AllowNonClientPainting(this Form form, bool allowNCPaint) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_ALLOW_NCPAINT, allowNCPaint); /// Cloaks the window such that it is not visible to the user. The window is still composed by DWM. /// The form. /// If set to true, cloak. - public static void Cloak(this Form form, bool cloak) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_CLOAK, cloak); + public static void Cloak(this Form form, bool cloak) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_CLOAK, cloak); /// Enables or forcibly disables DWM transitions. /// The form. /// true to disable transitions. - public static void DisableTransitions(this Form form, bool forceDisabled) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, forceDisabled); + public static void DisableTransitions(this Form form, bool forceDisabled) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, forceDisabled); /// - /// Do not show peek preview for the window. The peek view shows a full-sized preview of the window when the mouse hovers over the window's thumbnail in - /// the taskbar. + /// Do not show peek preview for the window. The peek view shows a full-sized preview of the window when the mouse hovers over the + /// window's thumbnail in the taskbar. /// /// The form. /// - /// if set to true, hovering the mouse pointer over the window's thumbnail dismisses peek (in case another window in the group has a peek preview showing). + /// if set to true, hovering the mouse pointer over the window's thumbnail dismisses peek (in case another window in the group + /// has a peek preview showing). /// - public static void DisallowPeekPreview(this Form form, bool disallowPeek) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_DISALLOW_PEEK, disallowPeek); + public static void DisallowPeekPreview(this Form form, bool disallowPeek) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_DISALLOW_PEEK, disallowPeek); /// Enable the Aero "Blur Behind" effect on the whole client area. Background must be black. /// The window. @@ -197,7 +205,9 @@ namespace Vanara.Windows.Forms /// The graphics area on which the region resides. /// The region within the client area to apply the blur behind. /// true to enable blur behind for this region, false to disable it. - /// true if the window's colorization should transition to match the maximized windows; otherwise, false. + /// + /// true if the window's colorization should transition to match the maximized windows; otherwise, false. + /// public static void EnableBlurBehind(this IWin32Window window, Graphics graphics, Region region, bool enabled, bool transitionOnMaximized) { if (window == null) @@ -253,30 +263,32 @@ namespace Vanara.Windows.Forms } /// - /// Issues a flush call that blocks the caller until the next present, when all of the Microsoft DirectX surface updates that are currently outstanding - /// have been made. This compensates for very complex scenes or calling processes with very low priority. + /// Issues a flush call that blocks the caller until the next present, when all of the Microsoft DirectX surface updates that are + /// currently outstanding have been made. This compensates for very complex scenes or calling processes with very low priority. /// public static void Flush() => DwmFlush().ThrowIfFailed(); /// - /// Forces the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot representation of the window is - /// available. This value normally is set during a window's creation and not changed throughout the window's lifetime. Some scenarios, however, might - /// require the value to change over time. + /// Forces the window to display an iconic thumbnail or peek representation (a static bitmap), even if a live or snapshot + /// representation of the window is available. This value normally is set during a window's creation and not changed throughout the + /// window's lifetime. Some scenarios, however, might require the value to change over time. /// /// The form. /// true to require a iconic thumbnail or peek representation; otherwise, false. - public static void ForceIconicRepresentation(this Form form, bool iconRep) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FORCE_ICONIC_REPRESENTATION, iconRep); + public static void ForceIconicRepresentation(this Form form, bool iconRep) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FORCE_ICONIC_REPRESENTATION, iconRep); - /// Freeze the window's thumbnail image with its current visuals. Do no further live updates on the thumbnail image - /// to match the window's contents. + /// + /// Freeze the window's thumbnail image with its current visuals. Do no further live updates on the thumbnail image to match the + /// window's contents. + /// /// The form. /// if set to true freeze thumbnail. - public static void FreezeLiveThumbnail(this Form form, bool freeze) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FREEZE_REPRESENTATION, freeze); + public static void FreezeLiveThumbnail(this Form form, bool freeze) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FREEZE_REPRESENTATION, freeze); /// Retrieves the bounds of the caption button area in the window-relative space. /// The form. /// The bounds. - public static Rectangle GetCaptionButtonBounds(this Form form) => GetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_CAPTION_BUTTON_BOUNDS); + public static Rectangle GetCaptionButtonBounds(this Form form) => GetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_CAPTION_BUTTON_BOUNDS); /// If the window is cloaked, provides a value explaining why. /// The form. @@ -286,7 +298,7 @@ namespace Vanara.Windows.Forms /// Retrieves the extended frame bounds rectangle in screen space. /// The form. /// The bounds. - public static Rectangle GetExtendedFrameBounds(this Form form) => GetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS); + public static Rectangle GetExtendedFrameBounds(this Form form) => GetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS); /// Gets the live client thumbnail. /// The window. @@ -294,18 +306,22 @@ namespace Vanara.Windows.Forms public static LiveThumbnail GetLiveClientThumbnail(this IWin32Window window) => new LiveThumbnail(window); /// - /// The window will provide a bitmap for use by DWM as an iconic thumbnail or peek representation (a static bitmap) - /// for the window. DWMWA_HAS_ICONIC_BITMAP can be specified with DWMWA_FORCE_ICONIC_REPRESENTATION. DWMWA_HAS_ICONIC_BITMAP normally is set during a - /// window's creation and not changed throughout the window's lifetime. Some scenarios, however, might require the value to change over time. + /// The window will provide a bitmap for use by DWM as an iconic thumbnail or peek representation (a static bitmap) for the window. + /// DWMWA_HAS_ICONIC_BITMAP can be specified with DWMWA_FORCE_ICONIC_REPRESENTATION. DWMWA_HAS_ICONIC_BITMAP normally is set during a + /// window's creation and not changed throughout the window's lifetime. Some scenarios, however, might require the value to change + /// over time. /// /// The form. /// if set to true inform DWM that the window will provide an iconic thumbnail or peek representation. - public static void HasIconicBitmap(this Form form, bool hasIcon) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_HAS_ICONIC_BITMAP, hasIcon); + public static void HasIconicBitmap(this Form form, bool hasIcon) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_HAS_ICONIC_BITMAP, hasIcon); /// - /// Called by an application to indicate that all previously provided iconic bitmaps from a window, both thumbnails and peek representations, should be refreshed. + /// Called by an application to indicate that all previously provided iconic bitmaps from a window, both thumbnails and peek + /// representations, should be refreshed. /// - /// The window or tab whose bitmaps are being invalidated through this call. This window must belong to the calling process. + /// + /// The window or tab whose bitmaps are being invalidated through this call. This window must belong to the calling process. + /// public static void InvalidateIconicBitmaps(this IWin32Window window) => DwmInvalidateIconicBitmaps(window.Handle).ThrowIfFailed(); /// Discovers whether non-client rendering is enabled. @@ -316,22 +332,22 @@ namespace Vanara.Windows.Forms /// Specifies whether non-client content is right-to-left (RTL) mirrored. /// The form. /// if set to true the non-client content is right-to-left (RTL) mirrored. - public static void NonClientRightToLeft(this Form form, bool rtl) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_NONCLIENT_RTL_LAYOUT, rtl); + public static void NonClientRightToLeft(this Form form, bool rtl) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_NONCLIENT_RTL_LAYOUT, rtl); /// Prevents a window from fading to a glass sheet when peek is invoked. /// The form. /// if set to true prevent the window from fading during another window's peek. - public static void PreventFadingOnPeekPreview(this Form form, bool prevent) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_EXCLUDED_FROM_PEEK, prevent); + public static void PreventFadingOnPeekPreview(this Form form, bool prevent) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_EXCLUDED_FROM_PEEK, prevent); /// Sets how Flip3D treats the window. /// The form. /// The policy. - public static void SetFlip3DPolicy(this Form form, Flip3DWindowPolicy policy) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FLIP3D_POLICY, (DWMFLIP3DWINDOWPOLICY)policy); + public static void SetFlip3DPolicy(this Form form, Flip3DWindowPolicy policy) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_FLIP3D_POLICY, (DWMFLIP3DWINDOWPOLICY)policy); /// Sets the non-client rendering policy. /// The form. /// The policy. - public static void SetNonClientRenderingPolicy(this Form form, NonClientRenderingPolicy policy) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, (DWMNCRENDERINGPOLICY)policy); + public static void SetNonClientRenderingPolicy(this Form form, NonClientRenderingPolicy policy) => SetWindowAttribute(form, DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, (DWMNCRENDERINGPOLICY)policy); private static void AddEventHandler(object id, EventHandler value) { @@ -360,11 +376,12 @@ namespace Vanara.Windows.Forms return ptr.ToStructure(); } } + /// Indicates whether Desktop Window Manager (DWM) composition is enabled. /// true if is composition enabled; otherwise, false. private static bool IsCompositionEnabled() { - if (!CompositionSupported || !global::System.IO.File.Exists(global::System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"dwmapi.dll"))) + if (!CompositionSupported || !System.IO.File.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"dwmapi.dll"))) return false; DwmIsCompositionEnabled(out var res); return res; @@ -394,7 +411,9 @@ namespace Vanara.Windows.Forms { private Dictionary thumbnails = new Dictionary(); - public ThumbnailMgr() { } + public ThumbnailMgr() + { + } public void Dispose() { @@ -429,11 +448,11 @@ namespace Vanara.Windows.Forms } } - [global::System.Security.Permissions.PermissionSet(global::System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] - [global::System.Security.SecuritySafeCritical] + [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] + [SecuritySafeCritical] private class MessageWindow : NativeWindow, IDisposable { - [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public MessageWindow() { var cp = new CreateParams { Style = 0, ExStyle = 0, ClassStyle = 0, Parent = IntPtr.Zero, Caption = GetType().Name }; @@ -442,7 +461,7 @@ namespace Vanara.Windows.Forms public void Dispose() => DestroyHandle(); - [global::System.Security.Permissions.PermissionSet(global::System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] + [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] protected override void WndProc(ref Message m) { // ReSharper disable InconsistentNaming