using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
namespace Vanara.PInvoke
{
public static partial class Gdi32
{
/// The type of region.
[PInvokeData("wingdi.h", MSDNShortId = "15990903-8a48-4c47-b527-269d775255a5")]
public enum RDH
{
/// Rectangle region type.
RDH_RECTANGLES = 1
}
/// A mode indicating how the two regions will be combined.
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_COMB
{
/// Creates the intersection of the two combined regions.
RGN_AND = 1,
/// Creates the union of two combined regions.
RGN_OR = 2,
/// Creates the union of two combined regions except for any overlapping areas.
RGN_XOR = 3,
/// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
RGN_DIFF = 4,
/// Creates a copy of the region identified by hrgnSrc1.
RGN_COPY = 5,
}
/// The fill mode used to determine which pixels are in the region.
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_FILLMODE
{
/// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
ALTERNATE,
/// Selects winding mode (fills any region with a nonzero winding value).
WINDING
}
/// The type of the resulting region.
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_TYPE
{
/// No region is created.
ERROR = 0,
/// The region is empty.
NULLREGION = 1,
/// The region is a single rectangle.
SIMPLEREGION = 2,
/// The region is more than a single rectangle.
COMPLEXREGION = 3,
}
///
/// The CombineRgn function combines two regions and stores the result in a third region. The two regions are combined
/// according to the specified mode.
///
///
/// A handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn
/// is called.)
///
/// A handle to the first of two regions to be combined.
/// A handle to the second of two regions to be combined.
///
/// A mode indicating how the two regions will be combined. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// RGN_AND
/// Creates the intersection of the two combined regions.
///
/// -
/// RGN_COPY
/// Creates a copy of the region identified by hrgnSrc1.
///
/// -
/// RGN_DIFF
/// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
///
/// -
/// RGN_OR
/// Creates the union of two combined regions.
///
/// -
/// RGN_XOR
/// Creates the union of two combined regions except for any overlapping areas.
///
///
///
///
/// The return value specifies the type of the resulting region. It can be one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// NULLREGION
/// The region is empty.
///
/// -
/// SIMPLEREGION
/// The region is a single rectangle.
///
/// -
/// COMPLEXREGION
/// The region is more than a single rectangle.
///
/// -
/// ERROR
/// No region is created.
///
///
///
/// The three regions need not be distinct. For example, the hrgnSrc1 parameter can equal the hrgnDest parameter.
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-combinergn int CombineRgn( HRGN hrgnDst, HRGN hrgnSrc1, HRGN
// hrgnSrc2, int iMode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public static extern RGN_TYPE CombineRgn(HRGN hrgnDst, HRGN hrgnSrc1, HRGN hrgnSrc2, RGN_COMB iMode);
/// The CreateEllipticRgn function creates an elliptical region.
/// Specifies the x-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse.
/// Specifies the y-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse.
/// Specifies the x-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse.
/// Specifies the y-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse.
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
///
/// A bounding rectangle defines the size, shape, and orientation of the region: The long sides of the rectangle define the length of
/// the ellipse's major axis; the short sides define the length of the ellipse's minor axis; and the center of the rectangle defines
/// the intersection of the major and minor axes.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createellipticrgn HRGN CreateEllipticRgn( int x1, int y1,
// int x2, int y2 );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "b4e9b210-8e22-42db-bb6e-65f1fb870eff")]
public static extern SafeHRGN CreateEllipticRgn(int x1, int y1, int x2, int y2);
/// The CreateEllipticRgnIndirect function creates an elliptical region.
///
/// Pointer to a RECT structure that contains the coordinates of the upper-left and lower-right corners of the bounding rectangle of
/// the ellipse in logical units.
///
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
///
/// A bounding rectangle defines the size, shape, and orientation of the region: The long sides of the rectangle define the length of
/// the ellipse's major axis; the short sides define the length of the ellipse's minor axis; and the center of the rectangle defines
/// the intersection of the major and minor axes.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createellipticrgnindirect HRGN CreateEllipticRgnIndirect(
// const RECT *lprect );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "bd30516e-1e05-4b7d-a6bf-7512cf3ef30f")]
public static extern SafeHRGN CreateEllipticRgnIndirect(in RECT lprect);
/// The CreatePolygonRgn function creates a polygonal region.
///
/// A pointer to an array of POINT structures that define the vertices of the polygon in logical units. The polygon is presumed
/// closed. Each vertex can be specified only once.
///
/// The number of points in the array.
///
/// The fill mode used to determine which pixels are in the region. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ALTERNATE
/// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
///
/// -
/// WINDING
/// Selects winding mode (fills any region with a nonzero winding value).
///
///
/// For more information about these modes, see the SetPolyFillMode function.
///
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
/// Region coordinates are represented as 27-bit signed integers.
///
/// Regions created by the Create<shape>Rgn methods (such as CreateRectRgn and CreatePolygonRgn) only include the
/// interior of the shape; the shape's outline is excluded from the region. This means that any point on a line between two
/// sequential vertices is not included in the region. If you were to call PtInRegion for such a point, it would return zero as the result.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpolygonrgn HRGN CreatePolygonRgn( const POINT *pptl,
// int cPoint, int iMode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "dd7ad6de-c5f2-46e4-8d28-24caaa48ba3a")]
public static extern SafeHRGN CreatePolygonRgn(POINT pptl, int cPoint, RGN_FILLMODE iMode);
/// The CreatePolyPolygonRgn function creates a region consisting of a series of polygons. The polygons can overlap.
///
/// A pointer to an array of POINT structures that define the vertices of the polygons in logical units. The polygons are specified
/// consecutively. Each polygon is presumed closed and each vertex is specified only once.
///
///
/// A pointer to an array of integers, each of which specifies the number of points in one of the polygons in the array pointed to by lppt.
///
/// The total number of integers in the array pointed to by lpPolyCounts.
///
/// The fill mode used to determine which pixels are in the region. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ALTERNATE
/// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
///
/// -
/// WINDING
/// Selects winding mode (fills any region with a nonzero winding value).
///
///
/// For more information about these modes, see the SetPolyFillMode function.
///
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is zero.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
/// Region coordinates are represented as 27-bit signed integers.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpolypolygonrgn HRGN CreatePolyPolygonRgn( const POINT
// *pptl, const INT *pc, int cPoly, int iMode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "1113d3dc-8e3f-436c-a5a8-191785bc7fcc")]
public static extern SafeHRGN CreatePolyPolygonRgn([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] POINT[] pptl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] int[] pc, int cPoly, RGN_FILLMODE iMode);
/// The CreateRectRgn function creates a rectangular region.
/// Specifies the x-coordinate of the upper-left corner of the region in logical units.
/// Specifies the y-coordinate of the upper-left corner of the region in logical units.
/// Specifies the x-coordinate of the lower-right corner of the region in logical units.
/// Specifies the y-coordinate of the lower-right corner of the region in logical units.
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
/// Region coordinates are represented as 27-bit signed integers.
///
/// Regions created by the Create<shape>Rgn methods (such as CreateRectRgn and CreatePolygonRgn) only include the
/// interior of the shape; the shape's outline is excluded from the region. This means that any point on a line between two
/// sequential vertices is not included in the region. If you were to call PtInRegion for such a point, it would return zero as the result.
///
/// Examples
/// For an example, see Drawing Markers.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createrectrgn HRGN CreateRectRgn( int x1, int y1, int x2,
// int y2 );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "17456440-c655-48ab-8d1e-ee770330f164")]
public static extern SafeHRGN CreateRectRgn(int x1, int y1, int x2, int y2);
/// The CreateRectRgnIndirect function creates a rectangular region.
///
/// Pointer to a RECT structure that contains the coordinates of the upper-left and lower-right corners of the rectangle that defines
/// the region in logical units.
///
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object, call the DeleteObject function to delete it.
/// Region coordinates are represented as 27-bit signed integers.
/// The region will be exclusive of the bottom and right edges.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createrectrgnindirect HRGN CreateRectRgnIndirect( const RECT
// *lprect );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "f32e0b94-ce9c-4098-81fe-b239a9544621")]
public static extern SafeHRGN CreateRectRgnIndirect(in RECT lprect);
/// The CreateRoundRectRgn function creates a rectangular region with rounded corners.
/// Specifies the x-coordinate of the upper-left corner of the region in device units.
/// Specifies the y-coordinate of the upper-left corner of the region in device units.
/// Specifies the x-coordinate of the lower-right corner of the region in device units.
/// Specifies the y-coordinate of the lower-right corner of the region in device units.
/// Specifies the width of the ellipse used to create the rounded corners in device units.
/// Specifies the height of the ellipse used to create the rounded corners in device units.
///
/// If the function succeeds, the return value is the handle to the region.
/// If the function fails, the return value is NULL.
///
///
/// When you no longer need the HRGN object call the DeleteObject function to delete it.
/// Region coordinates are represented as 27-bit signed integers.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createroundrectrgn HRGN CreateRoundRectRgn( int x1, int y1,
// int x2, int y2, int w, int h );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "16f387e1-b00c-4755-8b21-1ee0f25bc46b")]
public static extern SafeHRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int w, int h);
///
/// The EqualRgn function checks the two specified regions to determine whether they are identical. The function considers two
/// regions identical if they are equal in size and shape.
///
/// Handle to a region.
/// Handle to a region.
///
/// If the two regions are equal, the return value is nonzero.
///
/// If the two regions are not equal, the return value is zero. A return value of ERROR means at least one of the region handles is invalid.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-equalrgn BOOL EqualRgn( HRGN hrgn1, HRGN hrgn2 );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "c7829998-78f4-4334-bf34-92aad12555f5")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EqualRgn(HRGN hrgn1, HRGN hrgn2);
/// The ExtCreateRegion function creates a region from the specified region and transformation data.
///
/// A pointer to an XFORM structure that defines the transformation to be performed on the region. If this pointer is NULL,
/// the identity transformation is used.
///
/// The number of bytes pointed to by lpRgnData.
/// A pointer to a RGNDATA structure that contains the region data in logical units.
///
/// If the function succeeds, the return value is the value of the region.
/// If the function fails, the return value is NULL.
///
///
/// Region coordinates are represented as 27-bit signed integers.
/// An application can retrieve data for a region by calling the GetRegionData function.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-extcreateregion HRGN ExtCreateRegion( const XFORM *lpx,
// DWORD nCount, const RGNDATA *lpData );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "4dcff824-eb1d-425c-b246-db4ace2c6518")]
public static extern SafeHRGN ExtCreateRegion(in XFORM lpx, uint nCount, [In] RGNDATA lpData);
/// The FillRgn function fills a region by using the specified brush.
/// Handle to the device context.
/// Handle to the region to be filled. The region's coordinates are presumed to be in logical units.
/// Handle to the brush to be used to fill the region.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-fillrgn BOOL FillRgn( HDC hdc, HRGN hrgn, HBRUSH hbr );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "c4e0eca5-442b-462b-a4f2-0c628b6d3d38")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FillRgn(HDC hdc, HRGN hrgn, HBRUSH hbr);
/// The FrameRgn function draws a border around the specified region by using the specified brush.
/// Handle to the device context.
///
/// Handle to the region to be enclosed in a border. The region's coordinates are presumed to be in logical units.
///
/// Handle to the brush to be used to draw the border.
/// Specifies the width, in logical units, of vertical brush strokes.
/// Specifies the height, in logical units, of horizontal brush strokes.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-framergn BOOL FrameRgn( HDC hdc, HRGN hrgn, HBRUSH hbr, int
// w, int h );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "d2c95392-7950-4963-8f10-2387daf23e93")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FrameRgn(HDC hdc, HRGN hrgn, HBRUSH hbr, int w, int h);
/// The GetPolyFillMode function retrieves the current polygon fill mode.
/// Handle to the device context.
///
/// If the function succeeds, the return value specifies the polygon fill mode, which can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ALTERNATE
/// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
///
/// -
/// WINDING
/// Selects winding mode (fills any region with a nonzero winding value).
///
///
/// If an error occurs, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getpolyfillmode int GetPolyFillMode( HDC hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "febf96fb-bf2e-4eb2-ab5f-89741a1decad")]
public static extern RGN_FILLMODE GetPolyFillMode(HDC hdc);
///
/// The GetRegionData function fills the specified buffer with data describing a region. This data includes the dimensions of
/// the rectangles that make up the region.
///
/// A handle to the region.
/// The size, in bytes, of the lpRgnData buffer.
///
/// A pointer to a RGNDATA structure that receives the information. The dimensions of the region are in logical units. If this
/// parameter is NULL, the return value contains the number of bytes needed for the region data.
///
///
///
/// If the function succeeds and dwCount specifies an adequate number of bytes, the return value is always dwCount. If dwCount is too
/// small or the function fails, the return value is 0. If lpRgnData is NULL, the return value is the required number of bytes.
///
/// If the function fails, the return value is zero.
///
/// The GetRegionData function is used in conjunction with the ExtCreateRegion function.
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getregiondata DWORD GetRegionData( HRGN hrgn, DWORD nCount,
// LPRGNDATA lpRgnData );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "e0d4862d-a405-4c00-b7b0-af4dd60407c0")]
public static extern uint GetRegionData(HRGN hrgn, uint nCount, [In, Out] RGNDATA lpRgnData);
/// The GetRgnBox function retrieves the bounding rectangle of the specified region.
/// A handle to the region.
/// A pointer to a RECT structure that receives the bounding rectangle in logical units.
///
/// The return value specifies the region's complexity. It can be one of the following values:
///
///
/// Value
/// Meaning
///
/// -
/// NULLREGION
/// Region is empty.
///
/// -
/// SIMPLEREGION
/// Region is a single rectangle.
///
/// -
/// COMPLEXREGION
/// Region is more than a single rectangle.
///
///
/// If the hrgn parameter does not identify a valid region, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getrgnbox int GetRgnBox( HRGN hrgn, LPRECT lprc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "42d06f7f-1bf3-418f-a3b9-c009cf2de10b")]
public static extern RGN_TYPE GetRgnBox(HRGN hrgn, out RECT lprc);
/// The InvertRgn function inverts the colors in the specified region.
/// Handle to the device context.
///
/// Handle to the region for which colors are inverted. The region's coordinates are presumed to be logical coordinates.
///
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
///
///
/// On monochrome screens, the InvertRgn function makes white pixels black and black pixels white. On color screens, this
/// inversion is dependent on the type of technology used to generate the colors for the screen.
///
/// Examples
/// For an example, see Using Brushes.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-invertrgn BOOL InvertRgn( HDC hdc, HRGN hrgn );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "94704c44-796a-4ca7-97f3-6676d7f94078")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InvertRgn(HDC hdc, HRGN hrgn);
/// The OffsetRgn function moves a region by the specified offsets.
/// Handle to the region to be moved.
/// Specifies the number of logical units to move left or right.
/// Specifies the number of logical units to move up or down.
///
/// The return value specifies the new region's complexity. It can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// NULLREGION
/// Region is empty.
///
/// -
/// SIMPLEREGION
/// Region is a single rectangle.
///
/// -
/// COMPLEXREGION
/// Region is more than one rectangle.
///
/// -
/// ERROR
/// An error occurred; region is unaffected.
///
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-offsetrgn int OffsetRgn( HRGN hrgn, int x, int y );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "5228c614-3278-4852-a867-7eed57359aef")]
public static extern RGN_TYPE OffsetRgn(HRGN hrgn, int x, int y);
/// The PaintRgn function paints the specified region by using the brush currently selected into the device context.
/// Handle to the device context.
/// Handle to the region to be filled. The region's coordinates are presumed to be logical coordinates.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-paintrgn BOOL PaintRgn( HDC hdc, HRGN hrgn );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "7656fb67-d865-459e-b379-4f2e44c76fd0")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PaintRgn(HDC hdc, HRGN hrgn);
/// The PtInRegion function determines whether the specified point is inside the specified region.
/// Handle to the region to be examined.
/// Specifies the x-coordinate of the point in logical units.
/// Specifies the y-coordinate of the point in logical units.
///
/// If the specified point is in the region, the return value is nonzero.
/// If the specified point is not in the region, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-ptinregion BOOL PtInRegion( HRGN hrgn, int x, int y );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "6fab6126-4672-49d6-825b-66a7927a7e99")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool PtInRegion(HRGN hrgn, int x, int y);
///
/// The RectInRegion function determines whether any part of the specified rectangle is within the boundaries of a region.
///
/// Handle to the region.
///
/// Pointer to a RECT structure containing the coordinates of the rectangle in logical units. The lower and right edges of the
/// rectangle are not included.
///
///
/// If any part of the specified rectangle lies within the boundaries of the region, the return value is nonzero.
/// If no part of the specified rectangle lies within the boundaries of the region, the return value is zero.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-rectinregion BOOL RectInRegion( HRGN hrgn, const RECT
// *lprect );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "198a02f1-120c-4f65-aa7c-a41f2e5e81a9")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RectInRegion(HRGN hrgn, in RECT lprect);
/// The SetPolyFillMode function sets the polygon fill mode for functions that fill polygons.
/// A handle to the device context.
///
/// The new fill mode. This parameter can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// ALTERNATE
/// Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line).
///
/// -
/// WINDING
/// Selects winding mode (fills any region with a nonzero winding value).
///
///
///
/// The return value specifies the previous filling mode. If an error occurs, the return value is zero.
///
///
/// In general, the modes differ only in cases where a complex, overlapping polygon must be filled (for example, a five-sided polygon
/// that forms a five-pointed star with a pentagon in the center). In such cases, ALTERNATE mode fills every other enclosed region
/// within the polygon (that is, the points of the star), but WINDING mode fills all regions (that is, the points and the pentagon).
///
///
/// When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and even-numbered polygon sides on each scan line. That
/// is, GDI fills the area between the first and second side, between the third and fourth side, and so on.
///
///
/// When the fill mode is WINDING, GDI fills any region that has a nonzero winding value. This value is defined as the number of
/// times a pen used to draw the polygon would go around the region. The direction of each edge of the polygon is important.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpolyfillmode int SetPolyFillMode( HDC hdc, int mode );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "233926c4-2658-405d-89b6-05ece844623d")]
public static extern RGN_FILLMODE SetPolyFillMode(HDC hdc, RGN_FILLMODE mode);
/// The SetRectRgn function converts a region into a rectangular region with the specified coordinates.
/// Handle to the region.
/// Specifies the x-coordinate of the upper-left corner of the rectangular region in logical units.
/// Specifies the y-coordinate of the upper-left corner of the rectangular region in logical units.
/// Specifies the x-coordinate of the lower-right corner of the rectangular region in logical units.
/// Specifies the y-coordinate of the lower-right corner of the rectangular region in logical units.
///
/// If the function succeeds, the return value is nonzero.
/// If the function fails, the return value is zero.
///
/// The region does not include the lower and right boundaries of the rectangle.
// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setrectrgn
// BOOL SetRectRgn( HRGN hrgn, int left, int top, int right, int bottom );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "9a024d61-f397-43d8-a48e-edb8102a6f55")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetRectRgn(HRGN hrgn, int left, int top, int right, int bottom);
/// The RGNDATAHEADER structure describes the data returned by the GetRegionData function.
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_rgndataheader typedef struct _RGNDATAHEADER { DWORD dwSize;
// DWORD iType; DWORD nCount; DWORD nRgnSize; RECT rcBound; } RGNDATAHEADER, *PRGNDATAHEADER;
[PInvokeData("wingdi.h", MSDNShortId = "15990903-8a48-4c47-b527-269d775255a5")]
[StructLayout(LayoutKind.Sequential)]
public struct RGNDATAHEADER
{
/// The size, in bytes, of the header.
public uint dwSize;
/// The type of region. This value must be RDH_RECTANGLES.
public RDH iType;
/// The number of rectangles that make up the region.
public uint nCount;
///
/// The size of the RGNDATA buffer required to receive the RECT structures that make up the region. If the size is not known,
/// this member can be zero.
///
public int nRgnSize;
/// A bounding rectangle for the region in logical units.
public RECT rcBound;
}
///
/// The RGNDATA structure contains a header and an array of rectangles that compose a region. The rectangles are sorted top to
/// bottom, left to right. They do not overlap.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_rgndata typedef struct _RGNDATA { RGNDATAHEADER rdh; char
// Buffer[1]; } RGNDATA, *PRGNDATA, *NPRGNDATA, *LPRGNDATA;
[PInvokeData("wingdi.h", MSDNShortId = "3eac0b23-3138-4b34-9c16-6cc185e4de22")]
[StructLayout(LayoutKind.Sequential)]
public class RGNDATA : IDisposable
{
///
/// A RGNDATAHEADER structure. The members of this structure specify the type of region (whether it is rectangular or
/// trapezoidal), the number of rectangles that make up the region, the size of the buffer that contains the rectangle
/// structures, and so on.
///
public RGNDATAHEADER rdh;
private IntPtr _Buffer;
/// Specifies an arbitrary-size buffer that contains the RECT structures that make up the region.
public RECT[] Buffer
{
get => _Buffer.ToArray((int)rdh.nCount);
set
{
((IDisposable)this).Dispose();
value = value ?? new RECT[0];
_Buffer = value.MarshalToPtr(Marshal.AllocHGlobal, out rdh.nRgnSize);
rdh.nCount = (uint)value.Length;
}
}
/// Gets the size, in bytes, of the structure with allocated memory for .
public uint Size => rdh.dwSize + (uint)rdh.nRgnSize;
/// Initializes a new instance of the class.
/// A bounding rectangle for the region in logical units.
/// The number of rectangles that make up the region.
public RGNDATA(in RECT bounds, int count)
{
rdh.dwSize = (uint)Marshal.SizeOf(typeof(RGNDATAHEADER));
rdh.iType = RDH.RDH_RECTANGLES;
Buffer = new RECT[count];
rdh.rcBound = bounds;
}
/// Initializes a new instance of the class.
/// A bounding rectangle for the region in logical units.
/// The RECT structures that make up the region.
public RGNDATA(in RECT bounds, RECT[] rects)
{
rdh.dwSize = (uint)Marshal.SizeOf(typeof(RGNDATAHEADER));
rdh.iType = RDH.RDH_RECTANGLES;
Buffer = rects;
rdh.rcBound = bounds;
}
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
void IDisposable.Dispose() { Marshal.FreeHGlobal(_Buffer); _Buffer = IntPtr.Zero; }
}
}
}