// THIS FILE IS PART OF Vanara PROJECT // THE Vanara PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License. // COPYRIGHT (C) dahall. ALL RIGHTS RESERVED. // GITHUB: https://github.com/dahall/Vanara using System.Runtime.InteropServices; namespace Vanara.PInvoke { /// Encapsulates classes exposed by DWNAPI.DLL public static partial class DwmApi { /// Extends the window frame into the client area. /// The handle to the window in which the frame will be extended into the client area. /// /// A pointer to a MARGINS structure that describes the margins to use when extending the frame into the client area. /// /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. [DllImport("dwmapi.dll", SetLastError = false, ExactSpelling = true)] [System.Security.SecurityCritical] [PInvokeData("dwmapi.h")] public static extern void DwmExtendFrameIntoClientArea(HWND hWnd, in MARGINS pMarInset); /// Returned by the GetThemeMargins function to define the margins of windows that have visual styles applied. [StructLayout(LayoutKind.Sequential)] [PInvokeData("dwmapi.h")] public struct MARGINS { /// Width of the left border that retains its size. public int cxLeftWidth; /// Width of the right border that retains its size. public int cxRightWidth; /// Height of the top border that retains its size. public int cyTopHeight; /// Height of the bottom border that retains its size. public int cyBottomHeight; /// Retrieves a instance with all values set to 0. public static readonly MARGINS Empty = new MARGINS(0); /// Retrieves a instance with all values set to -1. public static readonly MARGINS Infinite = new MARGINS(-1); /// Initializes a new instance of the struct. /// The left border value. /// The right border value. /// The top border value. /// The bottom border value. public MARGINS(int left, int right, int top, int bottom) { cxLeftWidth = left; cxRightWidth = right; cyTopHeight = top; cyBottomHeight = bottom; } /// Initializes a new instance of the struct. /// Value to assign to all margins. public MARGINS(int allMargins) => cxLeftWidth = cxRightWidth = cyTopHeight = cyBottomHeight = allMargins; /// Gets or sets the left border value. /// The left border. public int Left { get => cxLeftWidth; set => cxLeftWidth = value; } /// Gets or sets the right border value. /// The right border. public int Right { get => cxRightWidth; set => cxRightWidth = value; } /// Gets or sets the top border value. /// The top border. public int Top { get => cyTopHeight; set => cyTopHeight = value; } /// Gets or sets the bottom border value. /// The bottom border. public int Bottom { get => cyBottomHeight; set => cyBottomHeight = value; } /// Determines if two values are not equal. /// The first margin. /// The second margin. /// true if the values are unequal; false otherwise. public static bool operator !=(MARGINS m1, MARGINS m2) => !m1.Equals(m2); /// Determines if two values are equal. /// The first margin. /// The second margin. /// true if the values are equal; false otherwise. public static bool operator ==(MARGINS m1, MARGINS m2) => m1.Equals(m2); /// Determines whether the specified , is equal to this instance. /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object obj) => obj is MARGINS m2 ? cxLeftWidth == m2.cxLeftWidth && cxRightWidth == m2.cxRightWidth && cyTopHeight == m2.cyTopHeight && cyBottomHeight == m2.cyBottomHeight : base.Equals(obj); /// Returns a hash code for this instance. /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. public override int GetHashCode() { int RotateLeft(int value, int nBits) { nBits = nBits % 0x20; return (value << nBits) | (value >> (0x20 - nBits)); } return cxLeftWidth ^ RotateLeft(cyTopHeight, 8) ^ RotateLeft(cxRightWidth, 0x10) ^ RotateLeft(cyBottomHeight, 0x18); } /// Returns a that represents this instance. /// A that represents this instance. public override string ToString() => $"{{Left={cxLeftWidth},Right={cxRightWidth},Top={cyTopHeight},Bottom={cyBottomHeight}}}"; } } }