/// <summary>
 /// Gets the specified window attribute from the Desktop Window Manager (DWM).
 /// </summary>
 /// <typeparam name="T">Return type. Must match the attribute.</typeparam>
 /// <param name="window">The window.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns>Value of the windows attribute.</returns>
 public static T GetWindowAttribute <T>(this IWin32Window window, GetWindowAttr attribute) where T : struct
 {
     if (window == null)
     {
         throw new ArgumentNullException(nameof(window));
     }
     using (var ptr = System.Runtime.InteropServices.SafeHGlobalHandle.AllocHGlobal <T>())
     {
         NativeMethods.DwmGetWindowAttribute(window.Handle, (NativeMethods.DWMWINDOWATTRIBUTE)attribute, ptr, ptr.Size);
         return(ptr.ToStructure <T>());
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the specified window attribute from the Desktop Window Manager (DWM).
 /// </summary>
 /// <typeparam name="T">Return type. Must match the attribute.</typeparam>
 /// <param name="window">The window.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns>Value of the windows attribute.</returns>
 public static T GetWindowAttribute <T>(this IWin32Window window, GetWindowAttr attribute) where T : struct
 {
     if (window == null)
     {
         throw new ArgumentNullException(nameof(window));
     }
     using (var ptr = SafeCoTaskMemHandle.AllocCoTaskMem <T>())
     {
         DwmGetWindowAttribute(window.Handle, (DWMWINDOWATTRIBUTE)attribute, (IntPtr)ptr, ptr.Size);
         return(ptr.ToStructure <T>());
     }
 }