using System.Diagnostics; using System.Runtime.InteropServices; using ProtonVPN.OperatingSystems.WebAuthn.Interop; namespace ProtonVPN.OperatingSystems.WebAuthn; /// /// Represents a window handle. /// [StructLayout(LayoutKind.Sequential)] public struct WindowHandle { private nint _handle; /// /// /// /// public WindowHandle(nint handle) { _handle = handle; } /// /// Indicates whether the window handle is valid. /// public bool IsValid => _handle != nint.Zero; /// /// /// /// /// /// public static bool operator ==(WindowHandle a, WindowHandle b) => a._handle == b._handle; /// /// /// /// /// /// public static bool operator !=(WindowHandle a, WindowHandle b) => a._handle != b._handle; /// /// /// /// /// public override bool Equals(object obj) => obj is WindowHandle handle && handle._handle == _handle; /// /// /// /// public override int GetHashCode() => _handle.GetHashCode(); /// /// Gets the window handle of the foreground window associated with the calling process. /// public static WindowHandle ForegroundWindow => NativeMethods.GetForegroundWindow(); /// /// Gets the window handle of the main window of the calling process. /// public static WindowHandle MainWindow => new(Process.GetCurrentProcess().MainWindowHandle); /// /// Retrieves the window handle used by the console associated with the calling process. /// public static WindowHandle ConsoleWindow => NativeMethods.GetConsoleWindow(); }