chore: formatted FullScreenHelper code

This commit is contained in:
NaBian committed 2021-12-20 23:19:49 +08:00
1 parent 0fde3d1838
commit d1e117993a
6 files changed
+426 -635

No files matched your search

@@ -72,7 +72,7 @@ namespace HandyControl.Tools.Interop
string lpszWindow);
[DllImport(InteropValues.ExternDll.User32)]
internal static extern int GetWindowRect(IntPtr hwnd, out InteropValues.RECT lpRect);
internal static extern bool GetWindowRect(IntPtr hwnd, out InteropValues.RECT lpRect);
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
internal static extern bool GetCursorPos(out InteropValues.POINT pt);
@@ -380,14 +380,9 @@ namespace HandyControl.Tools.Interop
internal static int GetWindowLong(IntPtr hWnd, InteropValues.GWL nIndex) => GetWindowLong(hWnd, (int) nIndex);
internal static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
if (IntPtr.Size == 4)
{
return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
}
return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
}
internal static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) => IntPtr.Size == 4
? SetWindowLongPtr32(hWnd, nIndex, dwNewLong)
: SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
internal static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
@@ -448,6 +443,10 @@ namespace HandyControl.Tools.Interop
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetMonitorInfo(IntPtr hMonitor, ref InteropValues.MONITORINFO monitorInfo);
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true)]
[ResourceExposure(ResourceScope.None)]
public static extern IntPtr MonitorFromRect(ref InteropValues.RECT rect, int flags);
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true)]
internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref InteropValues.BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
@@ -470,6 +469,9 @@ namespace HandyControl.Tools.Interop
[ResourceExposure(ResourceScope.None)]
internal static extern bool EnableWindow(IntPtr hWnd, bool enable);
[DllImport(InteropValues.ExternDll.User32)]
public static extern bool ShowWindow(IntPtr hwnd, InteropValues.SW nCmdShow);
[ReflectionPermission(SecurityAction.Assert, Unrestricted = true), SecurityPermission(SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)]
internal static object PtrToStructure(IntPtr lparam, Type cls) => Marshal.PtrToStructure(lparam, cls);
@@ -484,6 +486,23 @@ namespace HandyControl.Tools.Interop
[DllImport(InteropValues.ExternDll.DwmApi, EntryPoint = "DwmGetColorizationColor", PreserveSig = true)]
internal static extern int DwmGetColorizationColor(out uint pcrColorization, out bool pfOpaqueBlend);
[DllImport(InteropValues.ExternDll.DwmApi, ExactSpelling = true, SetLastError = true)]
internal static extern int DwmSetWindowAttribute(IntPtr hwnd, InteropValues.DwmWindowAttribute dwAttribute,
in int pvAttribute, uint cbAttribute);
[DllImport(InteropValues.ExternDll.User32, EntryPoint = "GetWindowLong")]
private static extern IntPtr GetWindowLongPtr32(IntPtr hWnd, int nIndex);
[DllImport(InteropValues.ExternDll.User32, EntryPoint = "GetWindowLongPtr")]
private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
internal static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex) =>
IntPtr.Size == 8 ? GetWindowLongPtr64(hWnd, nIndex) : GetWindowLongPtr32(hWnd, nIndex);
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref InteropValues.WINDOWPLACEMENT placement);
#endregion
internal class Gdip
@@ -37,6 +37,8 @@ namespace HandyControl.Tools.Interop
BI_RGB = 0,
DIB_RGB_COLORS = 0,
E_FAIL = unchecked((int) 0x80004005),
HWND_TOP = 0,
GWL_STYLE = -16,
NIF_MESSAGE = 0x00000001,
NIF_ICON = 0x00000002,
NIF_TIP = 0x00000004,
@@ -95,6 +97,7 @@ namespace HandyControl.Tools.Interop
SC_MAXIMIZE = 0xF030,
SC_RESTORE = 0xF120,
SRCCOPY = 0x00CC0020,
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
MONITOR_DEFAULTTONEAREST = 0x00000002;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -257,6 +260,38 @@ namespace HandyControl.Tools.Interop
get => Right - Left;
set => Right = Left + value;
}
public bool Equals(RECT other)
{
return Left == other.Left && Right == other.Right && Top == other.Top && Bottom == other.Bottom;
}
public override bool Equals(object obj)
{
return obj is RECT rectangle && Equals(rectangle);
}
public static bool operator ==(RECT left, RECT right)
{
return left.Equals(right);
}
public static bool operator !=(RECT left, RECT right)
{
return !(left == right);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = Left;
hashCode = (hashCode * 397) ^ Top;
hashCode = (hashCode * 397) ^ Right;
hashCode = (hashCode * 397) ^ Bottom;
return hashCode;
}
}
}
internal struct BLENDFUNCTION
@@ -327,11 +362,11 @@ namespace HandyControl.Tools.Interop
}
[StructLayout(LayoutKind.Sequential)]
internal class WINDOWPLACEMENT
internal struct WINDOWPLACEMENT
{
public int length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
public int flags;
public int showCmd;
public SW showCmd;
public POINT ptMinPosition;
public POINT ptMaxPosition;
public RECT rcNormalPosition;
@@ -978,7 +1013,7 @@ namespace HandyControl.Tools.Interop
}
[Flags]
public enum WindowPositionFlags
internal enum WindowPositionFlags
{
/// <summary>
/// If the calling thread and the thread that owns the window are attached to different input queues, the system posts
@@ -1064,5 +1099,81 @@ namespace HandyControl.Tools.Interop
/// </summary>
SWP_SHOWWINDOW = 0x0040
}
[StructLayout(LayoutKind.Sequential)]
internal struct WindowPosition
{
public IntPtr Hwnd;
public IntPtr HwndZOrderInsertAfter;
public int X;
public int Y;
public int Width;
public int Height;
public WindowPositionFlags Flags;
}
[Flags]
internal enum DwmWindowAttribute : uint
{
DWMWA_NCRENDERING_ENABLED = 1,
DWMWA_NCRENDERING_POLICY,
DWMWA_TRANSITIONS_FORCEDISABLED,
DWMWA_ALLOW_NCPAINT,
DWMWA_CAPTION_BUTTON_BOUNDS,
DWMWA_NONCLIENT_RTL_LAYOUT,
DWMWA_FORCE_ICONIC_REPRESENTATION,
DWMWA_FLIP3D_POLICY,
DWMWA_EXTENDED_FRAME_BOUNDS,
DWMWA_HAS_ICONIC_BITMAP,
DWMWA_DISALLOW_PEEK,
DWMWA_EXCLUDED_FROM_PEEK,
DWMWA_LAST
}
[Flags]
internal enum WindowStyles
{
/// <summary>
/// The window is initially maximized.
/// </summary>
WS_MAXIMIZE = 0x01000000,
/// <summary>
/// The window has a maximize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must
/// also be specified.
/// </summary>
WS_MAXIMIZEBOX = 0x00010000,
/// <summary>
/// The window is initially minimized. Same as the WS_ICONIC style.
/// </summary>
WS_MINIMIZE = 0x20000000,
/// <summary>
/// The window has a sizing border. Same as the WS_SIZEBOX style.
/// </summary>
WS_THICKFRAME = 0x00040000,
}
/// <summary>
/// ShowWindow options
/// </summary>
internal enum SW
{
HIDE = 0,
SHOWNORMAL = 1,
NORMAL = 1,
SHOWMINIMIZED = 2,
SHOWMAXIMIZED = 3,
MAXIMIZE = 3,
SHOWNOACTIVATE = 4,
SHOW = 5,
MINIMIZE = 6,
SHOWMINNOACTIVE = 7,
SHOWNA = 8,
RESTORE = 9,
SHOWDEFAULT = 10,
FORCEMINIMIZE = 11,
}
}
}