#if PREVIEW_HANDLER using System; using System.Runtime.InteropServices; namespace ShellExtensions.Interop.Common { /// /// Wraps the native Windows MSG structure. /// public struct Message { /// /// Gets the window handle /// public IntPtr WindowHandle { get; } /// /// Gets the window message /// public uint Msg { get; } /// /// Gets the WParam /// public IntPtr WParam { get; } /// /// Gets the LParam /// public IntPtr LParam { get; } /// /// Gets the time /// public int Time { get; } /// /// Gets the point /// public NativePoint Point { get; } /// /// Creates a new instance of the Message struct /// /// Window handle /// Message /// WParam /// LParam /// Time /// Point internal Message(IntPtr windowHandle, uint msg, IntPtr wparam, IntPtr lparam, int time, NativePoint point) : this() { WindowHandle = windowHandle; Msg = msg; WParam = wparam; LParam = lparam; Time = time; Point = point; } /// /// Determines if two messages are equal. /// /// First message /// Second message /// True if first and second message are equal; false otherwise. public static bool operator ==(Message first, Message second) { return first.WindowHandle == second.WindowHandle && first.Msg == second.Msg && first.WParam == second.WParam && first.LParam == second.LParam && first.Time == second.Time && first.Point == second.Point; } /// /// Determines if two messages are not equal. /// /// First message /// Second message /// True if first and second message are not equal; false otherwise. public static bool operator !=(Message first, Message second) { return !(first == second); } /// /// Determines if this message is equal to another. /// /// Another message /// True if this message is equal argument; false otherwise. public override bool Equals(object obj) { return obj != null && obj is Message message && this == message; } /// /// Gets a hash code for the message. /// /// Hash code for this message. public override int GetHashCode() { int hash = WindowHandle.GetHashCode(); hash = hash * 31 + Msg.GetHashCode(); hash = hash * 31 + WParam.GetHashCode(); hash = hash * 31 + LParam.GetHashCode(); hash = hash * 31 + Time.GetHashCode(); hash = hash * 31 + Point.GetHashCode(); return hash; } } /// /// A wrapper for the native POINT structure. /// [StructLayout(LayoutKind.Sequential)] public struct NativePoint { /// /// Initialize the NativePoint /// /// The x coordinate of the point. /// The y coordinate of the point. public NativePoint(int x, int y) : this() { X = x; Y = y; } /// /// The X coordinate of the point /// public int X { get; set; } /// /// The Y coordinate of the point /// public int Y { get; set; } /// /// Determines if two NativePoints are equal. /// /// First NativePoint /// Second NativePoint /// True if first NativePoint is equal to the second; false otherwise. public static bool operator ==(NativePoint first, NativePoint second) { return first.X == second.X && first.Y == second.Y; } /// /// Determines if two NativePoints are not equal. /// /// First NativePoint /// Second NativePoint /// True if first NativePoint is not equal to the second; false otherwise. public static bool operator !=(NativePoint first, NativePoint second) { return !(first == second); } /// /// Determines if this NativePoint is equal to another. /// /// Another NativePoint to compare /// True if this NativePoint is equal obj; false otherwise. public override bool Equals(object obj) { return obj != null && obj is NativePoint point && this == point; } /// /// Gets a hash code for the NativePoint. /// /// Hash code for the NativePoint public override int GetHashCode() { int hash = X.GetHashCode(); hash = hash * 31 + Y.GetHashCode(); return hash; } } /// /// A wrapper for a RECT struct /// [StructLayout(LayoutKind.Sequential)] public struct NativeRect { /// /// Position of left edge /// public int Left { get; set; } /// /// Position of top edge /// public int Top { get; set; } /// /// Position of right edge /// public int Right { get; set; } /// /// Position of bottom edge /// public int Bottom { get; set; } /// /// Creates a new NativeRect initialized with supplied values. /// /// Position of left edge /// Position of top edge /// Position of right edge /// Position of bottom edge public NativeRect(int left, int top, int right, int bottom) : this() { Left = left; Top = top; Right = right; Bottom = bottom; } /// /// Determines if two NativeRects are equal. /// /// First NativeRect /// Second NativeRect /// True if first NativeRect is equal to second; false otherwise. public static bool operator ==(NativeRect first, NativeRect second) { return first.Left == second.Left && first.Top == second.Top && first.Right == second.Right && first.Bottom == second.Bottom; } /// /// Determines if two NativeRects are not equal /// /// First NativeRect /// Second NativeRect /// True if first is not equal to second; false otherwise. public static bool operator !=(NativeRect first, NativeRect second) { return !(first == second); } /// /// Determines if the NativeRect is equal to another Rect. /// /// Another NativeRect to compare /// True if this NativeRect is equal to the one provided; false otherwise. public override bool Equals(object obj) { return obj != null && obj is NativeRect rect && this == rect; } /// /// Creates a hash code for the NativeRect /// /// Returns hash code for this NativeRect public override int GetHashCode() { int hash = Left.GetHashCode(); hash = hash * 31 + Top.GetHashCode(); hash = hash * 31 + Right.GetHashCode(); hash = hash * 31 + Bottom.GetHashCode(); return hash; } } } #endif