Added color, OpenGL and region functions to Gdi32

pull/60/head
David Hall 2019-06-11 13:37:18 -06:00
parent 36116d7ff2
commit 70b0cf4393
3 changed files with 2352 additions and 0 deletions

View File

@ -0,0 +1,855 @@
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
namespace Vanara.PInvoke
{
public static partial class Gdi32
{
/// <summary>Specifies how the output image should be prepared.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "9a080f60-0bce-46b6-b8a8-f534ff83a0a8")]
public enum CA_FLAGS : ushort
{
/// <summary>Specifies that the negative of the original image should be displayed.</summary>
CA_NEGATIVE = 0x0001,
/// <summary>
/// Specifies that a logarithmic function should be applied to the final density of the output colors. This will increase the
/// color contrast when the luminance is low.
/// </summary>
CA_LOG_FILTER = 0x0002,
}
/// <summary>The type of standard light source under which the image is viewed.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "9a080f60-0bce-46b6-b8a8-f534ff83a0a8")]
public enum ILLUMINANT : ushort
{
/// <summary>Device's default. Standard used by output devices.</summary>
ILLUMINANT_DEVICE_DEFAULT = 0,
/// <summary>Tungsten lamp.</summary>
ILLUMINANT_A = 1,
/// <summary>Noon sunlight.</summary>
ILLUMINANT_B = 2,
/// <summary>NTSC daylight.</summary>
ILLUMINANT_C = 3,
/// <summary>Normal print.</summary>
ILLUMINANT_D50 = 4,
/// <summary>Bond paper print.</summary>
ILLUMINANT_D55 = 5,
/// <summary>Standard daylight. Standard for CRTs and pictures.</summary>
ILLUMINANT_D65 = 6,
/// <summary>Northern daylight.</summary>
ILLUMINANT_D75 = 7,
/// <summary>Cool white lamp.</summary>
ILLUMINANT_F2 = 8,
/// <summary>Same as ILLUMINANT_A.</summary>
ILLUMINANT_TUNGSTEN = ILLUMINANT_A,
/// <summary>Same as ILLUMINANT_C.</summary>
ILLUMINANT_DAYLIGHT = ILLUMINANT_C,
/// <summary>Same as ILLUMINANT_F2.</summary>
ILLUMINANT_FLUORESCENT = ILLUMINANT_F2,
/// <summary>Same as ILLUMINANT_C.</summary>
ILLUMINANT_NTSC = ILLUMINANT_C,
}
/// <summary>The alpha intensity value for the palette entry.</summary>
[PInvokeData("wingdi.h")]
public enum PC : byte
{
/// <summary>
/// Specifies that the low-order word of the logical palette entry designates a hardware palette index. This flag allows the
/// application to show the contents of the display device palette.
/// </summary>
PC_EXPLICIT = 0x2,
/// <summary>
/// Specifies that the color be placed in an unused entry in the system palette instead of being matched to an existing color in
/// the system palette. If there are no unused entries in the system palette, the color is matched normally. Once this color is
/// in the system palette, colors in other logical palettes can be matched to this color.
/// </summary>
PC_NOCOLLAPSE = 0x4,
/// <summary>
/// Specifies that the logical palette entry be used for palette animation. This flag prevents other windows from matching colors
/// to the palette entry since the color frequently changes. If an unused system-palette entry is available, the color is placed
/// in that entry. Otherwise, the color is not available for animation.
/// </summary>
PC_RESERVED = 0x1,
}
/// <summary>The current state of the system (physical) palette.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "0a9e7906-2f81-4fda-b03d-86feb0755327")]
public enum SYSPAL
{
/// <summary>The given device context is invalid or does not support a color palette.</summary>
SYSPAL_ERROR = 0,
/// <summary>The system palette contains static colors that will not change when an application realizes its logical palette.</summary>
SYSPAL_STATIC = 1,
/// <summary>The system palette contains no static colors except black and white.</summary>
SYSPAL_NOSTATIC = 2,
/// <summary>The system palette contains no static colors.</summary>
SYSPAL_NOSTATIC256 = 3,
}
/// <summary>The <c>AnimatePalette</c> function replaces entries in the specified logical palette.</summary>
/// <param name="hPal">A handle to the logical palette.</param>
/// <param name="iStartIndex">The first logical palette entry to be replaced.</param>
/// <param name="cEntries">The number of entries to be replaced.</param>
/// <param name="ppe">A pointer to the first member in an array of PALETTEENTRY structures used to replace the current entries.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// The <c>AnimatePalette</c> function only changes entries with the PC_RESERVED flag set in the corresponding <c>palPalEntry</c>
/// member of the LOGPALETTE structure.
/// </para>
/// <para>If the given palette is associated with the active window, the colors in the palette are replaced immediately.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-animatepalette BOOL AnimatePalette( HPALETTE hPal, UINT
// iStartIndex, UINT cEntries, const PALETTEENTRY *ppe );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "65dd45e2-39a4-4a94-bd14-b0c8e4a609a3")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AnimatePalette(HPALETTE hPal, uint iStartIndex, uint cEntries, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PALETTEENTRY[] ppe);
/// <summary>The <c>CreateHalftonePalette</c> function creates a halftone palette for the specified device context (DC).</summary>
/// <param name="hdc">A handle to the device context.</param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to a logical halftone palette.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application should create a halftone palette when the stretching mode of a device context is set to HALFTONE. The logical
/// halftone palette returned by <c>CreateHalftonePalette</c> should then be selected and realized into the device context before the
/// StretchBlt or StretchDIBits function is called.
/// </para>
/// <para>When you no longer need the palette, call the DeleteObject function to delete it.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createhalftonepalette HPALETTE CreateHalftonePalette( HDC
// hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "ba9dfa0c-98df-4922-acba-d00e9b4b0fb0")]
public static extern SafeHPALETTE CreateHalftonePalette(HDC hdc);
/// <summary>The <c>CreatePalette</c> function creates a logical palette.</summary>
/// <param name="plpal">A pointer to a LOGPALETTE structure that contains information about the colors in the logical palette.</param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to a logical palette.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// Once an application creates a logical palette, it can select that palette into a device context by calling the SelectPalette
/// function. A palette selected into a device context can be realized by calling the RealizePalette function.
/// </para>
/// <para>When you no longer need the palette, call the DeleteObject function to delete it.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpalette HPALETTE CreatePalette( const LOGPALETTE
// *plpal );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "f3462198-9360-4b77-ac62-9fe21ec666be")]
public static extern SafeHPALETTE CreatePalette([In] LOGPALETTE plpal);
/// <summary>The <c>GetColorAdjustment</c> function retrieves the color adjustment values for the specified device context (DC).</summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="lpca">A pointer to a COLORADJUSTMENT structure that receives the color adjustment values.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getcoloradjustment BOOL GetColorAdjustment( HDC hdc,
// LPCOLORADJUSTMENT lpca );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "405c0d0d-9433-4f4a-9957-5c42a0fb3a07")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetColorAdjustment(HDC hdc, ref COLORADJUSTMENT lpca);
/// <summary>
/// The <c>GetNearestColor</c> function retrieves a color value identifying a color from the system palette that will be displayed
/// when the specified color value is used.
/// </summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="color">A color value that identifies a requested color. To create a COLORREF color value, use the RGB macro.</param>
/// <returns>
/// <para>
/// If the function succeeds, the return value identifies a color from the system palette that corresponds to the given color value.
/// </para>
/// <para>If the function fails, the return value is CLR_INVALID.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getnearestcolor COLORREF GetNearestColor( HDC hdc, COLORREF
// color );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "89e4e19b-47be-442e-8eb4-c867bb78f36a")]
public static extern COLORREF GetNearestColor(HDC hdc, COLORREF color);
/// <summary>
/// The <c>GetNearestPaletteIndex</c> function retrieves the index for the entry in the specified logical palette most closely
/// matching a specified color value.
/// </summary>
/// <returns>
/// <para>If the function succeeds, the return value is the index of an entry in a logical palette.</para>
/// <para>If the function fails, the return value is CLR_INVALID.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the <c>GetDeviceCaps</c> function and
/// specifying the RASTERCAPS constant.
/// </para>
/// <para>If the given logical palette contains entries with the PC_EXPLICIT flag set, the return value is undefined.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/previous-versions/dd144903(v%3dvs.85) UINT GetNearestPaletteIndex( _In_ HPALETTE hpal, _In_
// COLORREF crColor );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Wingdi.h")]
public static extern uint GetNearestPaletteIndex(HPALETTE hpal, COLORREF crColor);
/// <summary>The <c>GetPaletteEntries</c> function retrieves a specified range of palette entries from the given logical palette.</summary>
/// <param name="hpal">A handle to the logical palette.</param>
/// <param name="iStart">The first entry in the logical palette to be retrieved.</param>
/// <param name="cEntries">The number of entries in the logical palette to be retrieved.</param>
/// <param name="pPalEntries">
/// A pointer to an array of PALETTEENTRY structures to receive the palette entries. The array must contain at least as many
/// structures as specified by the nEntries parameter.
/// </param>
/// <returns>
/// <para>
/// If the function succeeds and the handle to the logical palette is a valid pointer (not <c>NULL</c>), the return value is the
/// number of entries retrieved from the logical palette. If the function succeeds and handle to the logical palette is <c>NULL</c>,
/// the return value is the number of entries in the given palette.
/// </para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// If the nEntries parameter specifies more entries than exist in the palette, the remaining members of the PALETTEENTRY structure
/// are not altered.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getpaletteentries UINT GetPaletteEntries( HPALETTE hpal,
// UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "5e72e881-32e1-458e-a09e-91fa13abe178")]
public static extern uint GetPaletteEntries(HPALETTE hpal, uint iStart, uint cEntries, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PALETTEENTRY[] pPalEntries);
/// <summary>
/// The <c>GetSystemPaletteEntries</c> function retrieves a range of palette entries from the system palette that is associated with
/// the specified device context (DC).
/// </summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="iStart">The first entry to be retrieved from the system palette.</param>
/// <param name="cEntries">The number of entries to be retrieved from the system palette.</param>
/// <param name="pPalEntries">
/// A pointer to an array of PALETTEENTRY structures to receive the palette entries. The array must contain at least as many
/// structures as specified by the nEntries parameter. If this parameter is <c>NULL</c>, the function returns the total number of
/// entries in the palette.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the number of entries retrieved from the palette.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getsystempaletteentries UINT GetSystemPaletteEntries( HDC
// hdc, UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "67bb0adf-ae7f-48d5-bc62-82ece45aeee6")]
public static extern uint GetSystemPaletteEntries(HDC hdc, uint iStart, uint cEntries, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PALETTEENTRY[] pPalEntries);
/// <summary>
/// The <c>GetSystemPaletteUse</c> function retrieves the current state of the system (physical) palette for the specified device
/// context (DC).
/// </summary>
/// <param name="hdc">A handle to the device context.</param>
/// <returns>
/// <para>
/// If the function succeeds, the return value is the current state of the system palette. This parameter can be one of the following values.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>SYSPAL_NOSTATIC</term>
/// <term>The system palette contains no static colors except black and white.</term>
/// </item>
/// <item>
/// <term>SYSPAL_STATIC</term>
/// <term>The system palette contains static colors that will not change when an application realizes its logical palette.</term>
/// </item>
/// <item>
/// <term>SYSPAL_ERROR</term>
/// <term>The given device context is invalid or does not support a color palette.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// By default, the system palette contains 20 static colors that are not changed when an application realizes its logical palette.
/// An application can gain access to most of these colors by calling the SetSystemPaletteUse function.
/// </para>
/// <para>The device context identified by the hdc parameter must represent a device that supports color palettes.</para>
/// <para>
/// An application can determine whether a device supports color palettes by calling the GetDeviceCaps function and specifying the
/// RASTERCAPS constant.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getsystempaletteuse UINT GetSystemPaletteUse( HDC hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "0a9e7906-2f81-4fda-b03d-86feb0755327")]
public static extern SYSPAL GetSystemPaletteUse(HDC hdc);
/// <summary>The <c>RealizePalette</c> function maps palette entries from the current logical palette to the system palette.</summary>
/// <param name="hdc">A handle to the device context into which a logical palette has been selected.</param>
/// <returns>
/// <para>If the function succeeds, the return value is the number of entries in the logical palette mapped to the system palette.</para>
/// <para>If the function fails, the return value is GDI_ERROR.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// The <c>RealizePalette</c> function modifies the palette for the device associated with the specified device context. If the
/// device context is a memory DC, the color table for the bitmap selected into the DC is modified. If the device context is a
/// display DC, the physical palette for that device is modified.
/// </para>
/// <para>
/// A logical palette is a buffer between color-intensive applications and the system, allowing these applications to use as many
/// colors as needed without interfering with colors displayed by other windows.
/// </para>
/// <para>
/// When an application's window has the focus and it calls the <c>RealizePalette</c> function, the system attempts to realize as
/// many of the requested colors as possible. The same is also true for applications with inactive windows.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-realizepalette UINT RealizePalette( HDC hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "1c744ad2-09bc-455f-bc3c-9a2583b57a30")]
public static extern uint RealizePalette(HDC hdc);
/// <summary>The <c>ResizePalette</c> function increases or decreases the size of a logical palette based on the specified value.</summary>
/// <param name="hpal">A handle to the palette to be changed.</param>
/// <param name="n">
/// <para>The number of entries in the palette after it has been resized.</para>
/// <para>The number of entries is limited to 1024.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// If an application calls <c>ResizePalette</c> to reduce the size of the palette, the entries remaining in the resized palette are
/// unchanged. If the application calls <c>ResizePalette</c> to enlarge the palette, the additional palette entries are set to black
/// (the red, green, and blue values are all 0) and their flags are set to zero.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-resizepalette BOOL ResizePalette( HPALETTE hpal, UINT n );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "77178869-cbfb-4b91-a5b0-7d0404e7534f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ResizePalette(HPALETTE hpal, uint n);
/// <summary>The <c>SelectPalette</c> function selects the specified logical palette into a device context.</summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="hPal">A handle to the logical palette to be selected.</param>
/// <param name="bForceBkgd">
/// <para>
/// Specifies whether the logical palette is forced to be a background palette. If this value is <c>TRUE</c>, the RealizePalette
/// function causes the logical palette to be mapped to the colors already in the physical palette in the best possible way. This is
/// always done, even if the window for which the palette is realized belongs to a thread without active focus.
/// </para>
/// <para>
/// If this value is <c>FALSE</c>, RealizePalette causes the logical palette to be copied into the device palette when the
/// application is in the foreground. (If the hdc parameter is a memory device context, this parameter is ignored.)
/// </para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is a handle to the device context's previous logical palette.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// An application can select a logical palette into more than one device context only if device contexts are compatible. Otherwise
/// <c>SelectPalette</c> fails. To create a device context that is compatible with another device context, call CreateCompatibleDC
/// with the first device context as the parameter. If a logical palette is selected into more than one device context, changes to
/// the logical palette will affect all device contexts for which it is selected.
/// </para>
/// <para>
/// An application might call the <c>SelectPalette</c> function with the bForceBackground parameter set to <c>TRUE</c> if the child
/// windows of a top-level window each realize their own palettes. However, only the child window that needs to realize its palette
/// must set bForceBackground to <c>TRUE</c>; other child windows must set this value to <c>FALSE</c>.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-selectpalette HPALETTE SelectPalette( HDC hdc, HPALETTE
// hPal, BOOL bForceBkgd );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "1fc3356f-6fa3-444f-b224-b953acd2394b")]
public static extern HPALETTE SelectPalette(HDC hdc, HPALETTE hPal, [MarshalAs(UnmanagedType.Bool)] bool bForceBkgd);
/// <summary>
/// The <c>SetColorAdjustment</c> function sets the color adjustment values for a device context (DC) using the specified values.
/// </summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="lpca">A pointer to a COLORADJUSTMENT structure containing the color adjustment values.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// The color adjustment values are used to adjust the input color of the source bitmap for calls to the StretchBlt and StretchDIBits
/// functions when HALFTONE mode is set.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setcoloradjustment BOOL SetColorAdjustment( HDC hdc, const
// COLORADJUSTMENT *lpca );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "292d6cdc-cafa-438a-9392-a9c22e7d44a5")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetColorAdjustment(HDC hdc, in COLORADJUSTMENT lpca);
/// <summary>
/// The <c>SetPaletteEntries</c> function sets RGB (red, green, blue) color values and flags in a range of entries in a logical palette.
/// </summary>
/// <param name="hpal">A handle to the logical palette.</param>
/// <param name="iStart">The first logical-palette entry to be set.</param>
/// <param name="cEntries">The number of logical-palette entries to be set.</param>
/// <param name="pPalEntries">
/// A pointer to the first member of an array of PALETTEENTRY structures containing the RGB values and flags.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the number of entries that were set in the logical palette.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// Even if a logical palette has been selected and realized, changes to the palette do not affect the physical palette in the
/// surface. RealizePalette must be called again to set the new logical palette into the surface.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpaletteentries UINT SetPaletteEntries( HPALETTE hpal,
// UINT iStart, UINT cEntries, const PALETTEENTRY *pPalEntries );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "df38f482-75ba-4800-8b26-92204c63255e")]
public static extern uint SetPaletteEntries(HPALETTE hpal, uint iStart, uint cEntries, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PALETTEENTRY[] pPalEntries);
/// <summary>
/// The <c>SetSystemPaletteUse</c> function allows an application to specify whether the system palette contains 2 or 20 static
/// colors. The default system palette contains 20 static colors. (Static colors cannot be changed when an application realizes a
/// logical palette.)
/// </summary>
/// <param name="hdc">A handle to the device context. This device context must refer to a device that supports color palettes.</param>
/// <param name="use">
/// <para>The new use of the system palette. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>SYSPAL_NOSTATIC</term>
/// <term>The system palette contains two static colors (black and white).</term>
/// </item>
/// <item>
/// <term>SYSPAL_NOSTATIC256</term>
/// <term>The system palette contains no static colors.</term>
/// </item>
/// <item>
/// <term>SYSPAL_STATIC</term>
/// <term>The system palette contains static colors that will not change when an application realizes its logical palette.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>
/// If the function succeeds, the return value is the previous system palette. It can be either SYSPAL_NOSTATIC, SYSPAL_NOSTATIC256,
/// or SYSPAL_STATIC.
/// </para>
/// <para>If the function fails, the return value is SYSPAL_ERROR.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// When an application window moves to the foreground and the SYSPAL_NOSTATIC value is set, the application must call the
/// GetSysColor function to save the current system colors setting. It must also call SetSysColors to set reasonable values using
/// only black and white. When the application returns to the background or terminates, the previous system colors must be restored.
/// </para>
/// <para>If the function returns SYSPAL_ERROR, the specified device context is invalid or does not support color palettes.</para>
/// <para>An application must call this function only when its window is maximized and has the input focus.</para>
/// <para>
/// If an application calls <c>SetSystemPaletteUse</c> with uUsage set to SYSPAL_NOSTATIC, the system continues to set aside two
/// entries in the system palette for pure white and pure black, respectively.
/// </para>
/// <para>After calling this function with uUsage set to SYSPAL_NOSTATIC, an application must take the following steps:</para>
/// <list type="number">
/// <item>
/// <term>Realize the logical palette.</term>
/// </item>
/// <item>
/// <term>Call the GetSysColor function to save the current system-color settings.</term>
/// </item>
/// <item>
/// <term>
/// Call the SetSysColors function to set the system colors to reasonable values using black and white. For example, adjacent or
/// overlapping items (such as window frames and borders) should be set to black and white, respectively.
/// </term>
/// </item>
/// <item>
/// <term>Send the WM_SYSCOLORCHANGE message to other top-level windows to allow them to be redrawn with the new system colors.</term>
/// </item>
/// </list>
/// <para>When the application's window loses focus or closes, the application must perform the following steps:</para>
/// <list type="number">
/// <item>
/// <term>Call <c>SetSystemPaletteUse</c> with the uUsage parameter set to SYSPAL_STATIC.</term>
/// </item>
/// <item>
/// <term>Realize the logical palette.</term>
/// </item>
/// <item>
/// <term>Restore the system colors to their previous values.</term>
/// </item>
/// <item>
/// <term>Send the WM_SYSCOLORCHANGE message.</term>
/// </item>
/// </list>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setsystempaletteuse UINT SetSystemPaletteUse( HDC hdc, UINT
// use );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "6ff245d3-1bcc-4778-a595-c1eb16531ad3")]
public static extern SYSPAL SetSystemPaletteUse(HDC hdc, SYSPAL use);
/// <summary>
/// The <c>UnrealizeObject</c> function resets the origin of a brush or resets a logical palette. If the hgdiobj parameter is a
/// handle to a brush, <c>UnrealizeObject</c> directs the system to reset the origin of the brush the next time it is selected. If
/// the hgdiobj parameter is a handle to a logical palette, <c>UnrealizeObject</c> directs the system to realize the palette as
/// though it had not previously been realized. The next time the application calls the RealizePalette function for the specified
/// palette, the system completely remaps the logical palette to the system palette.
/// </summary>
/// <param name="h">A handle to the logical palette to be reset.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// The <c>UnrealizeObject</c> function should not be used with stock objects. For example, the default palette, obtained by calling
/// GetStockObject (DEFAULT_PALETTE), is a stock object.
/// </para>
/// <para>A palette identified by hgdiobj can be the currently selected palette of a device context.</para>
/// <para>
/// If hgdiobj is a brush, <c>UnrealizeObject</c> does nothing, and the function returns <c>TRUE</c>. Use SetBrushOrgEx to set the
/// origin of a brush.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-unrealizeobject BOOL UnrealizeObject( HGDIOBJ h );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "b84cd0b3-fdf1-4f12-bc45-308032d6d698")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnrealizeObject(HGDIOBJ h);
/// <summary>
/// The <c>UpdateColors</c> function updates the client area of the specified device context by remapping the current colors in the
/// client area to the currently realized logical palette.
/// </summary>
/// <param name="hdc">A handle to the device context.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying
/// the RASTERCAPS constant.
/// </para>
/// <para>
/// An inactive window with a realized logical palette may call <c>UpdateColors</c> as an alternative to redrawing its client area
/// when the system palette changes.
/// </para>
/// <para>
/// The <c>UpdateColors</c> function typically updates a client area faster than redrawing the area. However, because
/// <c>UpdateColors</c> performs the color translation based on the color of each pixel before the system palette changed, each call
/// to this function results in the loss of some color accuracy.
/// </para>
/// <para>This function must be called soon after a WM_PALETTECHANGED message is received.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-updatecolors BOOL UpdateColors( HDC hdc );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "61dfd579-3fc9-4e0a-bfd9-d04c6f918fd8")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateColors(HDC hdc);
/// <summary>
/// The <c>COLORADJUSTMENT</c> structure defines the color adjustment values used by the StretchBlt and StretchDIBits functions when
/// the stretch mode is HALFTONE. You can set the color adjustment values by calling the SetColorAdjustment function.
/// </summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-coloradjustment typedef struct tagCOLORADJUSTMENT { WORD
// caSize; WORD caFlags; WORD caIlluminantIndex; WORD caRedGamma; WORD caGreenGamma; WORD caBlueGamma; WORD caReferenceBlack; WORD
// caReferenceWhite; SHORT caContrast; SHORT caBrightness; SHORT caColorfulness; SHORT caRedGreenTint; } COLORADJUSTMENT,
// *PCOLORADJUSTMENT, *LPCOLORADJUSTMENT;
[PInvokeData("wingdi.h", MSDNShortId = "9a080f60-0bce-46b6-b8a8-f534ff83a0a8")]
[StructLayout(LayoutKind.Sequential)]
public struct COLORADJUSTMENT
{
/// <summary>The size, in bytes, of the structure.</summary>
public ushort caSize;
/// <summary>
/// <para>
/// Specifies how the output image should be prepared. This member may be set to <c>NULL</c> or any combination of the following values.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>CA_NEGATIVE</term>
/// <term>Specifies that the negative of the original image should be displayed.</term>
/// </item>
/// <item>
/// <term>CA_LOG_FILTER</term>
/// <term>
/// Specifies that a logarithmic function should be applied to the final density of the output colors. This will increase the
/// color contrast when the luminance is low.
/// </term>
/// </item>
/// </list>
/// </summary>
public CA_FLAGS caFlags;
/// <summary>
/// <para>
/// The type of standard light source under which the image is viewed. This member may be set to one of the following values.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ILLUMINANT_DEVICE_DEFAULT</term>
/// <term>Device's default. Standard used by output devices.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_A</term>
/// <term>Tungsten lamp.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_B</term>
/// <term>Noon sunlight.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_C</term>
/// <term>NTSC daylight.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_D50</term>
/// <term>Normal print.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_D55</term>
/// <term>Bond paper print.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_D65</term>
/// <term>Standard daylight. Standard for CRTs and pictures.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_D75</term>
/// <term>Northern daylight.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_F2</term>
/// <term>Cool white lamp.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_TUNGSTEN</term>
/// <term>Same as ILLUMINANT_A.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_DAYLIGHT</term>
/// <term>Same as ILLUMINANT_C.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_FLUORESCENT</term>
/// <term>Same as ILLUMINANT_F2.</term>
/// </item>
/// <item>
/// <term>ILLUMINANT_NTSC</term>
/// <term>Same as ILLUMINANT_C.</term>
/// </item>
/// </list>
/// </summary>
public ILLUMINANT caIlluminantIndex;
/// <summary>
/// Specifies the n power gamma-correction value for the red primary of the source colors. The value must be in the range from
/// 2500 to 65,000. A value of 10,000 means no gamma correction.
/// </summary>
public ushort caRedGamma;
/// <summary>
/// Specifies the n power gamma-correction value for the green primary of the source colors. The value must be in the range from
/// 2500 to 65,000. A value of 10,000 means no gamma correction.
/// </summary>
public ushort caGreenGamma;
/// <summary>
/// Specifies the n power gamma-correction value for the blue primary of the source colors. The value must be in the range from
/// 2500 to 65,000. A value of 10,000 means no gamma correction.
/// </summary>
public ushort caBlueGamma;
/// <summary>
/// The black reference for the source colors. Any colors that are darker than this are treated as black. The value must be in
/// the range from 0 to 4000.
/// </summary>
public ushort caReferenceBlack;
/// <summary>
/// The white reference for the source colors. Any colors that are lighter than this are treated as white. The value must be in
/// the range from 6000 to 10,000.
/// </summary>
public ushort caReferenceWhite;
/// <summary>
/// The amount of contrast to be applied to the source object. The value must be in the range from -100 to 100. A value of 0
/// means no contrast adjustment.
/// </summary>
public short caContrast;
/// <summary>
/// The amount of brightness to be applied to the source object. The value must be in the range from -100 to 100. A value of 0
/// means no brightness adjustment.
/// </summary>
public short caBrightness;
/// <summary>
/// The amount of colorfulness to be applied to the source object. The value must be in the range from -100 to 100. A value of 0
/// means no colorfulness adjustment.
/// </summary>
public short caColorfulness;
/// <summary>
/// The amount of red or green tint adjustment to be applied to the source object. The value must be in the range from -100 to
/// 100. Positive numbers adjust toward red and negative numbers adjust toward green. Zero means no tint adjustment.
/// </summary>
public short caRedGreenTint;
}
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
[PInvokeData("wingdi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct PALETTEENTRY
{
/// <summary>
/// <para>Type: <c>BYTE</c></para>
/// <para>The red intensity value for the palette entry.</para>
/// </summary>
public byte peRed;
/// <summary>
/// <para>Type: <c>BYTE</c></para>
/// <para>The green intensity value for the palette entry.</para>
/// </summary>
public byte peGreen;
/// <summary>
/// <para>Type: <c>BYTE</c></para>
/// <para>The blue intensity value for the palette entry.</para>
/// </summary>
public byte peBlue;
/// <summary>
/// <para>Type: <c>BYTE</c></para>
/// <para>
/// The alpha intensity value for the palette entry. Note that as of DirectX 8, this member is treated differently than
/// documented for Windows.
/// </para>
/// </summary>
public PC peFlags;
}
/// <summary>The <c>LOGPALETTE</c> structure defines a logical palette.</summary>
/// <remarks>
/// The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are
/// most likely to be placed in the system palette.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
[StructLayout(LayoutKind.Sequential)]
public class LOGPALETTE : IDisposable
{
/// <summary>The version number of the system.</summary>
public ushort palVersion;
/// <summary>The number of entries in the logical palette.</summary>
public ushort palNumEntries;
private IntPtr _palPalEntry;
/// <summary>Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.</summary>
public PALETTEENTRY[] palPalEntry
{
get => _palPalEntry.ToArray<PALETTEENTRY>(palNumEntries);
set { Marshal.FreeHGlobal(_palPalEntry); value.MarshalToPtr(Marshal.AllocHGlobal, out _); }
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry);
}
}
}

View File

@ -0,0 +1,656 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Gdi32
{
/// <summary>A set of bit flags that specify properties of the pixel buffer.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")]
[Flags]
public enum PFD_FLAGS : uint
{
/// <summary>The buffer is double-buffered. This flag and PFD_SUPPORT_GDI are mutually exclusive in the current generic implementation.</summary>
PFD_DOUBLEBUFFER = 0x00000001,
/// <summary>The buffer is stereoscopic. This flag is not supported in the current generic implementation.</summary>
PFD_STEREO = 0x00000002,
/// <summary>The buffer can draw to a window or device surface.</summary>
PFD_DRAW_TO_WINDOW = 0x00000004,
/// <summary>The buffer can draw to a memory bitmap.</summary>
PFD_DRAW_TO_BITMAP = 0x00000008,
/// <summary>
/// The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER are mutually exclusive in the current generic implementation.
/// </summary>
PFD_SUPPORT_GDI = 0x00000010,
/// <summary>The buffer supports OpenGL drawing.</summary>
PFD_SUPPORT_OPENGL = 0x00000020,
/// <summary>
/// The pixel format is supported by the GDI software implementation, which is also known as the generic implementation. If this
/// bit is clear, the pixel format is supported by a device driver or hardware.
/// </summary>
PFD_GENERIC_FORMAT = 0x00000040,
/// <summary>
/// The buffer uses RGBA pixels on a palette-managed device. A logical palette is required to achieve the best results for this
/// pixel type. Colors in the palette should be specified according to the values of the cRedBits, cRedShift, cGreenBits,
/// cGreenShift, cBluebits, and cBlueShift members. The palette should be created and realized in the device context before
/// calling wglMakeCurrent.
/// </summary>
PFD_NEED_PALETTE = 0x00000080,
/// <summary>
/// Defined in the pixel format descriptors of hardware that supports one hardware palette in 256-color mode only. For such
/// systems to use hardware acceleration, the hardware palette must be in a fixed order (for example, 3-3-2) when in RGBA mode or
/// must match the logical palette when in color-index mode.When this flag is set, you must call SetSystemPaletteUse in your
/// program to force a one-to-one mapping of the logical palette and the system palette. If your OpenGL hardware supports
/// multiple hardware palettes and the device driver can allocate spare hardware palettes for OpenGL, this flag is typically clear.
/// <para>This flag is not set in the generic pixel formats.</para>
/// </summary>
PFD_NEED_SYSTEM_PALETTE = 0x00000100,
/// <summary>
/// Specifies the content of the back buffer in the double-buffered main color plane following a buffer swap. Swapping the color
/// buffers causes the exchange of the back buffer's content with the front buffer's content. Following the swap, the back
/// buffer's content contains the front buffer's content before the swap. PFD_SWAP_EXCHANGE is a hint only and might not be
/// provided by a driver.
/// </summary>
PFD_SWAP_EXCHANGE = 0x00000200,
/// <summary>
/// Specifies the content of the back buffer in the double-buffered main color plane following a buffer swap. Swapping the color
/// buffers causes the content of the back buffer to be copied to the front buffer. The content of the back buffer is not
/// affected by the swap. PFD_SWAP_COPY is a hint only and might not be provided by a driver.
/// </summary>
PFD_SWAP_COPY = 0x00000400,
/// <summary>
/// Indicates whether a device can swap individual layer planes with pixel formats that include double-buffered overlay or
/// underlay planes. Otherwise all layer planes are swapped together as a group. When this flag is set, wglSwapLayerBuffers is supported.
/// </summary>
PFD_SWAP_LAYER_BUFFERS = 0x00000800,
/// <summary>
/// The pixel format is supported by a device driver that accelerates the generic implementation. If this flag is clear and the
/// PFD_GENERIC_FORMAT flag is set, the pixel format is supported by the generic implementation only.
/// </summary>
PFD_GENERIC_ACCELERATED = 0x00001000,
/// <summary>The PFD support directdraw</summary>
PFD_SUPPORT_DIRECTDRAW = 0x00002000,
/// <summary>The PFD direc t3 d accelerated</summary>
PFD_DIRECT3D_ACCELERATED = 0x00004000,
/// <summary>The PFD support composition</summary>
PFD_SUPPORT_COMPOSITION = 0x00008000,
/// <summary>
/// The requested pixel format can either have or not have a depth buffer. To select a pixel format without a depth buffer, you
/// must specify this flag. The requested pixel format can be with or without a depth buffer. Otherwise, only pixel formats with
/// a depth buffer are considered.
/// </summary>
PFD_DEPTH_DONTCARE = 0x20000000,
/// <summary>The requested pixel format can be either single- or double-buffered.</summary>
PFD_DOUBLEBUFFER_DONTCARE = 0x40000000,
/// <summary>The requested pixel format can be either monoscopic or stereoscopic.</summary>
PFD_STEREO_DONTCARE = 0x80000000,
}
/// <summary>The plane layer.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")]
public enum PFD_LAYER : sbyte
{
/// <summary>The layer is the main plane.</summary>
PFD_MAIN_PLANE = 0,
/// <summary>The layer is the overlay plane.</summary>
PFD_OVERLAY_PLANE = 1,
/// <summary>The layer is the underlay plane.</summary>
PFD_UNDERLAY_PLANE = -1
}
/// <summary>Specifies the type of pixel data.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")]
public enum PFD_TYPE : byte
{
/// <summary>RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha.</summary>
PFD_TYPE_RGBA = 0,
/// <summary>Color-index pixels. Each pixel uses a color-index value.</summary>
PFD_TYPE_COLORINDEX = 1,
}
/// <summary>
/// The <c>ChoosePixelFormat</c> function attempts to match an appropriate pixel format supported by a device context to a given
/// pixel format specification.
/// </summary>
/// <param name="hdc">
/// Specifies the device context that the function examines to determine the best match for the pixel format descriptor pointed to by ppfd.
/// </param>
/// <param name="ppfd">
/// <para>
/// Pointer to a PIXELFORMATDESCRIPTOR structure that specifies the requested pixel format. In this context, the members of the
/// <c>PIXELFORMATDESCRIPTOR</c> structure that ppfd points to are used as follows:
/// </para>
/// <list type="table">
/// <listheader>
/// <term>nSize</term>
/// <term>Specifies the size of the PIXELFORMATDESCRIPTOR data structure. Set this member to .</term>
/// </listheader>
/// <item>
/// <term>nVersion</term>
/// <term>Specifies the version number of the PIXELFORMATDESCRIPTOR data structure. Set this member to 1.</term>
/// </item>
/// <item>
/// <term>dwFlags</term>
/// <term>
/// A set of bit flags that specify properties of the pixel buffer. You can combine the following bit flag constants by using
/// bitwise-OR. If any of the following flags are set, the ChoosePixelFormat function attempts to match pixel formats that also have
/// that flag or flags set. Otherwise, ChoosePixelFormat ignores that flag in the pixel formats: PFD_DRAW_TO_WINDOW,
/// PFD_DRAW_TO_BITMAP, PFD_SUPPORT_GDI, PFD_SUPPORT_OPENGL If any of the following flags are set, ChoosePixelFormat attempts to
/// match pixel formats that also have that flag or flags set. Otherwise, it attempts to match pixel formats without that flag set:
/// PFD_DOUBLEBUFFER PFD_STEREO If the following flag is set, the function ignores the PFD_DOUBLEBUFFER flag in the pixel formats:
/// PFD_DOUBLEBUFFER_DONTCARE If the following flag is set, the function ignores the PFD_STEREO flag in the pixel formats: PFD_STEREO_DONTCARE
/// </term>
/// </item>
/// <item>
/// <term>iPixelType</term>
/// <term>Specifies the type of pixel format for the function to consider: PFD_TYPE_RGBA, PFD_TYPE_COLORINDEX</term>
/// </item>
/// <item>
/// <term>cColorBits</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>cRedBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cRedShift</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cGreenBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cGreenShift</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cBlueBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cBlueShift</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cAlphaBits</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>cAlphaShift</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cAccumBits</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>cAccumRedBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cAccumGreenBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cAccumBlueBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cAccumAlphaBits</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>cDepthBits</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>cStencilBits</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>cAuxBuffers</term>
/// <term>Zero or greater.</term>
/// </item>
/// <item>
/// <term>iLayerType</term>
/// <term>Specifies one of the following layer type values: PFD_MAIN_PLANE, PFD_OVERLAY_PLANE, PFD_UNDERLAY_PLANE</term>
/// </item>
/// <item>
/// <term>bReserved</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>dwLayerMask</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>dwVisibleMask</term>
/// <term>Not used.</term>
/// </item>
/// <item>
/// <term>dwDamageMask</term>
/// <term>Not used.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>
/// If the function succeeds, the return value is a pixel format index (one-based) that is the closest match to the given pixel
/// format descriptor.
/// </para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// You must ensure that the pixel format matched by the <c>ChoosePixelFormat</c> function satisfies your requirements. For example,
/// if you request a pixel format with a 24-bit RGB color buffer but the device context offers only 8-bit RGB color buffers, the
/// function returns a pixel format with an 8-bit RGB color buffer.
/// </para>
/// <para>Examples</para>
/// <para>The following code sample shows how to use <c>ChoosePixelFormat</c> to match a specified pixel format.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-choosepixelformat int ChoosePixelFormat( HDC hdc, const
// PIXELFORMATDESCRIPTOR *ppfd );
[DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "17bd0a2c-5257-4ae3-80f4-a5ad536169fb")]
public static extern int ChoosePixelFormat(HDC hdc, in PIXELFORMATDESCRIPTOR ppfd);
/// <summary>
/// The <c>DescribePixelFormat</c> function obtains information about the pixel format identified by iPixelFormat of the device
/// associated with hdc. The function sets the members of the PIXELFORMATDESCRIPTOR structure pointed to by ppfd with that pixel
/// format data.
/// </summary>
/// <param name="hdc">Specifies the device context.</param>
/// <param name="iPixelFormat">
/// Index that specifies the pixel format. The pixel formats that a device context supports are identified by positive one-based
/// integer indexes.
/// </param>
/// <param name="nBytes">
/// The size, in bytes, of the structure pointed to by ppfd. The <c>DescribePixelFormat</c> function stores no more than nBytes bytes
/// of data to that structure. Set this value to <c>sizeof</c>( <c>PIXELFORMATDESCRIPTOR</c>).
/// </param>
/// <param name="ppfd">
/// Pointer to a <c>PIXELFORMATDESCRIPTOR</c> structure whose members the function sets with pixel format data. The function stores
/// the number of bytes copied to the structure in the structure's <c>nSize</c> member. If, upon entry, ppfd is <c>NULL</c>, the
/// function writes no data to the structure. This is useful when you only want to obtain the maximum pixel format index of a device context.
/// </param>
/// <returns>
/// <para>
/// If the function succeeds, the return value is the maximum pixel format index of the device context. In addition, the function
/// sets the members of the <c>PIXELFORMATDESCRIPTOR</c> structure pointed to by ppfd according to the specified pixel format.
/// </para>
/// <para>If the function fails, the return value is zero. To get extended error information, call GetLastError.</para>
/// </returns>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-describepixelformat int DescribePixelFormat( HDC hdc, int
// iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd );
[DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "9692a30d-c7d4-40c7-a265-72c4ebabd5f2")]
public static extern int DescribePixelFormat(HDC hdc, int iPixelFormat, uint nBytes, ref PIXELFORMATDESCRIPTOR ppfd);
/// <summary>The <c>GetEnhMetaFilePixelFormat</c> function retrieves pixel format information for an enhanced metafile.</summary>
/// <param name="hemf">Identifies the enhanced metafile.</param>
/// <param name="cbBuffer">Specifies the size, in bytes, of the buffer into which the pixel format information is copied.</param>
/// <param name="ppfd">
/// Pointer to a PIXELFORMATDESCRIPTOR structure that contains the logical pixel format specification. The metafile uses this
/// structure to record the logical pixel format specification.
/// </param>
/// <returns>
/// <para>If the function succeeds and finds a pixel format, the return value is the size of the metafile's pixel format.</para>
/// <para>If no pixel format is present, the return value is zero.</para>
/// <para>If an error occurs and the function fails, the return value is GDI_ERROR. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// When an enhanced metafile specifies a pixel format in its <c>ENHMETAHEADER</c> structure and the pixel format fits in the buffer,
/// the pixel format information is copied into ppfd. When cbBuffer is too small to contain the pixel format of the metafile, the
/// pixel format is not copied to the buffer. In either case, the function returns the size of the metafile's pixel format.
/// </para>
/// <para>For information on metafile recording and other operations, see Enhanced Metafile Operations.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getenhmetafilepixelformat UINT GetEnhMetaFilePixelFormat(
// HENHMETAFILE hemf, UINT cbBuffer, PIXELFORMATDESCRIPTOR *ppfd );
[DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "80209210-5caa-44a9-a791-991b257d8d28")]
public static extern uint GetEnhMetaFilePixelFormat(HENHMETAFILE hemf, uint cbBuffer, ref PIXELFORMATDESCRIPTOR ppfd);
/// <summary>
/// The <c>SetPixelFormat</c> function sets the pixel format of the specified device context to the format specified by the
/// iPixelFormat index.
/// </summary>
/// <param name="hdc">Specifies the device context whose pixel format the function attempts to set.</param>
/// <param name="format">
/// Index that identifies the pixel format to set. The various pixel formats supported by a device context are identified by
/// one-based indexes.
/// </param>
/// <param name="ppfd">
/// Pointer to a PIXELFORMATDESCRIPTOR structure that contains the logical pixel format specification. The system's metafile
/// component uses this structure to record the logical pixel format specification. The structure has no other effect upon the
/// behavior of the <c>SetPixelFormat</c> function.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is <c>TRUE</c>.</para>
/// <para>If the function fails, the return value is <c>FALSE</c>. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// If hdc references a window, calling the <c>SetPixelFormat</c> function also changes the pixel format of the window. Setting the
/// pixel format of a window more than once can lead to significant complications for the Window Manager and for multithread
/// applications, so it is not allowed. An application can only set the pixel format of a window one time. Once a window's pixel
/// format is set, it cannot be changed.
/// </para>
/// <para>
/// You should select a pixel format in the device context before calling the wglCreateContext function. The <c>wglCreateContext</c>
/// function creates a rendering context for drawing on the device in the selected pixel format of the device context.
/// </para>
/// <para>
/// An OpenGL window has its own pixel format. Because of this, only device contexts retrieved for the client area of an OpenGL
/// window are allowed to draw into the window. As a result, an OpenGL window should be created with the WS_CLIPCHILDREN and
/// WS_CLIPSIBLINGS styles. Additionally, the window class attribute should not include the CS_PARENTDC style.
/// </para>
/// <para>Examples</para>
/// <para>The following code example shows <c>SetPixelFormat</c> usage.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpixelformat BOOL SetPixelFormat( HDC hdc, int format,
// const PIXELFORMATDESCRIPTOR *ppfd );
[DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "f8d74078-a7e7-4d95-857a-f51d5d70598e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetPixelFormat(HDC hdc, int format, ref PIXELFORMATDESCRIPTOR ppfd);
/// <summary>
/// The <c>SwapBuffers</c> function exchanges the front and back buffers if the current pixel format for the window referenced by the
/// specified device context includes a back buffer.
/// </summary>
/// <param name="Arg1">
/// Specifies a device context. If the current pixel format for the window referenced by this device context includes a back buffer,
/// the function exchanges the front and back buffers.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is <c>TRUE</c>.</para>
/// <para>If the function fails, the return value is <c>FALSE</c>. To get extended error information, call GetLastError.</para>
/// </returns>
/// <remarks>
/// <para>
/// If the current pixel format for the window referenced by the device context does not include a back buffer, this call has no
/// effect and the content of the back buffer is undefined when the function returns.
/// </para>
/// <para>
/// With multithread applications, flush the drawing commands in any other threads drawing to the same window before calling <c>SwapBuffers</c>.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-swapbuffers BOOL SwapBuffers( HDC Arg1 );
[DllImport(Lib.Gdi32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "2c9728e4-c5be-4b14-a6f7-2899c792ec3d")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SwapBuffers(HDC Arg1);
/// <summary>The <c>PIXELFORMATDESCRIPTOR</c> structure describes the pixel format of a drawing surface.</summary>
/// <remarks>
/// Please notice carefully, as documented above, that certain pixel format properties are not supported in the current generic
/// implementation. The generic implementation is the Microsoft GDI software implementation of OpenGL. Hardware manufacturers may
/// enhance parts of OpenGL, and may support some pixel format properties not supported by the generic implementation.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpixelformatdescriptor typedef struct
// tagPIXELFORMATDESCRIPTOR { WORD nSize; WORD nVersion; DWORD dwFlags; BYTE iPixelType; BYTE cColorBits; BYTE cRedBits; BYTE
// cRedShift; BYTE cGreenBits; BYTE cGreenShift; BYTE cBlueBits; BYTE cBlueShift; BYTE cAlphaBits; BYTE cAlphaShift; BYTE cAccumBits;
// BYTE cAccumRedBits; BYTE cAccumGreenBits; BYTE cAccumBlueBits; BYTE cAccumAlphaBits; BYTE cDepthBits; BYTE cStencilBits; BYTE
// cAuxBuffers; BYTE iLayerType; BYTE bReserved; DWORD dwLayerMask; DWORD dwVisibleMask; DWORD dwDamageMask; } PIXELFORMATDESCRIPTOR,
// *PPIXELFORMATDESCRIPTOR, *LPPIXELFORMATDESCRIPTOR;
[PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")]
[StructLayout(LayoutKind.Sequential)]
public struct PIXELFORMATDESCRIPTOR
{
/// <summary>Specifies the size of this data structure. This value should be set to <c>sizeof</c>( <c>PIXELFORMATDESCRIPTOR</c>).</summary>
public ushort nSize;
/// <summary>Specifies the version of this data structure. This value should be set to 1.</summary>
public ushort nVersion;
/// <summary>
/// <para>
/// A set of bit flags that specify properties of the pixel buffer. The properties are generally not mutually exclusive; you can
/// set any combination of bit flags, with the exceptions noted. The following bit flag constants are defined.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>PFD_DRAW_TO_WINDOW</term>
/// <term>The buffer can draw to a window or device surface.</term>
/// </item>
/// <item>
/// <term>PFD_DRAW_TO_BITMAP</term>
/// <term>The buffer can draw to a memory bitmap.</term>
/// </item>
/// <item>
/// <term>PFD_SUPPORT_GDI</term>
/// <term>The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER are mutually exclusive in the current generic implementation.</term>
/// </item>
/// <item>
/// <term>PFD_SUPPORT_OPENGL</term>
/// <term>The buffer supports OpenGL drawing.</term>
/// </item>
/// <item>
/// <term>PFD_GENERIC_ACCELERATED</term>
/// <term>
/// The pixel format is supported by a device driver that accelerates the generic implementation. If this flag is clear and the
/// PFD_GENERIC_FORMAT flag is set, the pixel format is supported by the generic implementation only.
/// </term>
/// </item>
/// <item>
/// <term>PFD_GENERIC_FORMAT</term>
/// <term>
/// The pixel format is supported by the GDI software implementation, which is also known as the generic implementation. If this
/// bit is clear, the pixel format is supported by a device driver or hardware.
/// </term>
/// </item>
/// <item>
/// <term>PFD_NEED_PALETTE</term>
/// <term>
/// The buffer uses RGBA pixels on a palette-managed device. A logical palette is required to achieve the best results for this
/// pixel type. Colors in the palette should be specified according to the values of the cRedBits, cRedShift, cGreenBits,
/// cGreenShift, cBluebits, and cBlueShift members. The palette should be created and realized in the device context before
/// calling wglMakeCurrent.
/// </term>
/// </item>
/// <item>
/// <term>PFD_NEED_SYSTEM_PALETTE</term>
/// <term>
/// Defined in the pixel format descriptors of hardware that supports one hardware palette in 256-color mode only. For such
/// systems to use hardware acceleration, the hardware palette must be in a fixed order (for example, 3-3-2) when in RGBA mode or
/// must match the logical palette when in color-index mode.When this flag is set, you must call SetSystemPaletteUse in your
/// program to force a one-to-one mapping of the logical palette and the system palette. If your OpenGL hardware supports
/// multiple hardware palettes and the device driver can allocate spare hardware palettes for OpenGL, this flag is typically
/// clear. This flag is not set in the generic pixel formats.
/// </term>
/// </item>
/// <item>
/// <term>PFD_DOUBLEBUFFER</term>
/// <term>The buffer is double-buffered. This flag and PFD_SUPPORT_GDI are mutually exclusive in the current generic implementation.</term>
/// </item>
/// <item>
/// <term>PFD_STEREO</term>
/// <term>The buffer is stereoscopic. This flag is not supported in the current generic implementation.</term>
/// </item>
/// <item>
/// <term>PFD_SWAP_LAYER_BUFFERS</term>
/// <term>
/// Indicates whether a device can swap individual layer planes with pixel formats that include double-buffered overlay or
/// underlay planes. Otherwise all layer planes are swapped together as a group. When this flag is set, wglSwapLayerBuffers is supported.
/// </term>
/// </item>
/// </list>
/// <para>You can specify the following bit flags when calling ChoosePixelFormat.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>PFD_DEPTH_DONTCARE</term>
/// <term>
/// The requested pixel format can either have or not have a depth buffer. To select a pixel format without a depth buffer, you
/// must specify this flag. The requested pixel format can be with or without a depth buffer. Otherwise, only pixel formats with
/// a depth buffer are considered.
/// </term>
/// </item>
/// <item>
/// <term>PFD_DOUBLEBUFFER_DONTCARE</term>
/// <term>The requested pixel format can be either single- or double-buffered.</term>
/// </item>
/// <item>
/// <term>PFD_STEREO_DONTCARE</term>
/// <term>The requested pixel format can be either monoscopic or stereoscopic.</term>
/// </item>
/// </list>
/// <para>
/// With the <c>glAddSwapHintRectWIN</c> extension function, two new flags are included for the <c>PIXELFORMATDESCRIPTOR</c>
/// pixel format structure.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>PFD_SWAP_COPY</term>
/// <term>
/// Specifies the content of the back buffer in the double-buffered main color plane following a buffer swap. Swapping the color
/// buffers causes the content of the back buffer to be copied to the front buffer. The content of the back buffer is not
/// affected by the swap. PFD_SWAP_COPY is a hint only and might not be provided by a driver.
/// </term>
/// </item>
/// <item>
/// <term>PFD_SWAP_EXCHANGE</term>
/// <term>
/// Specifies the content of the back buffer in the double-buffered main color plane following a buffer swap. Swapping the color
/// buffers causes the exchange of the back buffer's content with the front buffer's content. Following the swap, the back
/// buffer's content contains the front buffer's content before the swap. PFD_SWAP_EXCHANGE is a hint only and might not be
/// provided by a driver.
/// </term>
/// </item>
/// </list>
/// </summary>
public PFD_FLAGS dwFlags;
/// <summary>
/// <para>Specifies the type of pixel data. The following types are defined.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>PFD_TYPE_RGBA</term>
/// <term>RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha.</term>
/// </item>
/// <item>
/// <term>PFD_TYPE_COLORINDEX</term>
/// <term>Color-index pixels. Each pixel uses a color-index value.</term>
/// </item>
/// </list>
/// </summary>
public PFD_TYPE iPixelType;
/// <summary>
/// Specifies the number of color bitplanes in each color buffer. For RGBA pixel types, it is the size of the color buffer,
/// excluding the alpha bitplanes. For color-index pixels, it is the size of the color-index buffer.
/// </summary>
public byte cColorBits;
/// <summary>Specifies the number of red bitplanes in each RGBA color buffer.</summary>
public byte cRedBits;
/// <summary>Specifies the shift count for red bitplanes in each RGBA color buffer.</summary>
public byte cRedShift;
/// <summary>Specifies the number of green bitplanes in each RGBA color buffer.</summary>
public byte cGreenBits;
/// <summary>Specifies the shift count for green bitplanes in each RGBA color buffer.</summary>
public byte cGreenShift;
/// <summary>Specifies the number of blue bitplanes in each RGBA color buffer.</summary>
public byte cBlueBits;
/// <summary>Specifies the shift count for blue bitplanes in each RGBA color buffer.</summary>
public byte cBlueShift;
/// <summary>Specifies the number of alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported.</summary>
public byte cAlphaBits;
/// <summary>Specifies the shift count for alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported.</summary>
public byte cAlphaShift;
/// <summary>Specifies the total number of bitplanes in the accumulation buffer.</summary>
public byte cAccumBits;
/// <summary>Specifies the number of red bitplanes in the accumulation buffer.</summary>
public byte cAccumRedBits;
/// <summary>Specifies the number of green bitplanes in the accumulation buffer.</summary>
public byte cAccumGreenBits;
/// <summary>Specifies the number of blue bitplanes in the accumulation buffer.</summary>
public byte cAccumBlueBits;
/// <summary>Specifies the number of alpha bitplanes in the accumulation buffer.</summary>
public byte cAccumAlphaBits;
/// <summary>Specifies the depth of the depth (z-axis) buffer.</summary>
public byte cDepthBits;
/// <summary>Specifies the depth of the stencil buffer.</summary>
public byte cStencilBits;
/// <summary>Specifies the number of auxiliary buffers. Auxiliary buffers are not supported.</summary>
public byte cAuxBuffers;
/// <summary>Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.</summary>
public byte iLayerType;
/// <summary>
/// Specifies the number of overlay and underlay planes. Bits 0 through 3 specify up to 15 overlay planes and bits 4 through 7
/// specify up to 15 underlay planes.
/// </summary>
public byte bReserved;
/// <summary>Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.</summary>
public PFD_LAYER dwLayerMask;
/// <summary>
/// Specifies the transparent color or index of an underlay plane. When the pixel type is RGBA, <c>dwVisibleMask</c> is a
/// transparent RGB color value. When the pixel type is color index, it is a transparent index value.
/// </summary>
public uint dwVisibleMask;
/// <summary>Ignored. Earlier implementations of OpenGL used this member, but it is no longer used.</summary>
public uint dwDamageMask;
}
}
}

View File

@ -0,0 +1,841 @@
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
namespace Vanara.PInvoke
{
public static partial class Gdi32
{
/// <summary>The type of region.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "15990903-8a48-4c47-b527-269d775255a5")]
public enum RDH
{
/// <summary>Rectangle region type.</summary>
RDH_RECTANGLES = 1
}
/// <summary>A mode indicating how the two regions will be combined.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_COMB
{
/// <summary>Creates the intersection of the two combined regions.</summary>
RGN_AND = 1,
/// <summary>Creates the union of two combined regions.</summary>
RGN_OR = 2,
/// <summary>Creates the union of two combined regions except for any overlapping areas.</summary>
RGN_XOR = 3,
/// <summary>Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.</summary>
RGN_DIFF = 4,
/// <summary>Creates a copy of the region identified by hrgnSrc1.</summary>
RGN_COPY = 5,
}
/// <summary>The type of the resulting region.</summary>
[PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")]
public enum RGN_TYPE
{
/// <summary>No region is created.</summary>
ERROR = 0,
/// <summary>The region is empty.</summary>
NULLREGION = 1,
/// <summary>The region is a single rectangle.</summary>
SIMPLEREGION = 2,
/// <summary>The region is more than a single rectangle.</summary>
COMPLEXREGION = 3,
}
/// <summary>
/// The <c>CombineRgn</c> function combines two regions and stores the result in a third region. The two regions are combined
/// according to the specified mode.
/// </summary>
/// <param name="hrgnDst">
/// A handle to a new region with dimensions defined by combining two other regions. (This region must exist before <c>CombineRgn</c>
/// is called.)
/// </param>
/// <param name="hrgnSrc1">A handle to the first of two regions to be combined.</param>
/// <param name="hrgnSrc2">A handle to the second of two regions to be combined.</param>
/// <param name="iMode">
/// <para>A mode indicating how the two regions will be combined. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>RGN_AND</term>
/// <term>Creates the intersection of the two combined regions.</term>
/// </item>
/// <item>
/// <term>RGN_COPY</term>
/// <term>Creates a copy of the region identified by hrgnSrc1.</term>
/// </item>
/// <item>
/// <term>RGN_DIFF</term>
/// <term>Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.</term>
/// </item>
/// <item>
/// <term>RGN_OR</term>
/// <term>Creates the union of two combined regions.</term>
/// </item>
/// <item>
/// <term>RGN_XOR</term>
/// <term>Creates the union of two combined regions except for any overlapping areas.</term>
/// </item>
/// </list>
/// </param>
/// <returns>
/// <para>The return value specifies the type of the resulting region. It can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>NULLREGION</term>
/// <term>The region is empty.</term>
/// </item>
/// <item>
/// <term>SIMPLEREGION</term>
/// <term>The region is a single rectangle.</term>
/// </item>
/// <item>
/// <term>COMPLEXREGION</term>
/// <term>The region is more than a single rectangle.</term>
/// </item>
/// <item>
/// <term>ERROR</term>
/// <term>No region is created.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>The three regions need not be distinct. For example, the hrgnSrc1 parameter can equal the hrgnDest parameter.</remarks>
// 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);
/// <summary>The <c>CreateEllipticRgn</c> function creates an elliptical region.</summary>
/// <param name="x1">Specifies the x-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse.</param>
/// <param name="y1">Specifies the y-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse.</param>
/// <param name="x2">Specifies the x-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse.</param>
/// <param name="y2">Specifies the y-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse.</param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the HRGN object, call the DeleteObject function to delete it.</para>
/// <para>
/// 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.
/// </para>
/// </remarks>
// 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);
/// <summary>The <c>CreateEllipticRgnIndirect</c> function creates an elliptical region.</summary>
/// <param name="lprect">
/// 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.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object, call the DeleteObject function to delete it.</para>
/// <para>
/// 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.
/// </para>
/// </remarks>
// 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);
/// <summary>The <c>CreatePolygonRgn</c> function creates a polygonal region.</summary>
/// <param name="pptl">
/// 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.
/// </param>
/// <param name="cPoint">The number of points in the array.</param>
/// <param name="iMode">
/// <para>The fill mode used to determine which pixels are in the region. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ALTERNATE</term>
/// <term>Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).</term>
/// </item>
/// <item>
/// <term>WINDING</term>
/// <term>Selects winding mode (fills any region with a nonzero winding value).</term>
/// </item>
/// </list>
/// <para>For more information about these modes, see the SetPolyFillMode function.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object, call the DeleteObject function to delete it.</para>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// <para>
/// Regions created by the Create&lt;shape&gt;Rgn methods (such as CreateRectRgn and <c>CreatePolygonRgn</c>) 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.
/// </para>
/// </remarks>
// 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(System.Drawing.Point pptl, int cPoint, System.Drawing.Drawing2D.FillMode iMode);
/// <summary>The <c>CreatePolyPolygonRgn</c> function creates a region consisting of a series of polygons. The polygons can overlap.</summary>
/// <param name="pptl">
/// 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.
/// </param>
/// <param name="pc">
/// 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.
/// </param>
/// <param name="cPoly">The total number of integers in the array pointed to by lpPolyCounts.</param>
/// <param name="iMode">
/// <para>The fill mode used to determine which pixels are in the region. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ALTERNATE</term>
/// <term>Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).</term>
/// </item>
/// <item>
/// <term>WINDING</term>
/// <term>Selects winding mode (fills any region with a nonzero winding value).</term>
/// </item>
/// </list>
/// <para>For more information about these modes, see the SetPolyFillMode function.</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object, call the DeleteObject function to delete it.</para>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// </remarks>
// 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)] System.Drawing.Point[] pptl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] int[] pc, int cPoly, System.Drawing.Drawing2D.FillMode iMode);
/// <summary>The <c>CreateRectRgn</c> function creates a rectangular region.</summary>
/// <param name="x1">Specifies the x-coordinate of the upper-left corner of the region in logical units.</param>
/// <param name="y1">Specifies the y-coordinate of the upper-left corner of the region in logical units.</param>
/// <param name="x2">Specifies the x-coordinate of the lower-right corner of the region in logical units.</param>
/// <param name="y2">Specifies the y-coordinate of the lower-right corner of the region in logical units.</param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object, call the DeleteObject function to delete it.</para>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// <para>
/// Regions created by the Create&lt;shape&gt;Rgn methods (such as <c>CreateRectRgn</c> 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.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Drawing Markers.</para>
/// </remarks>
// 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);
/// <summary>The <c>CreateRectRgnIndirect</c> function creates a rectangular region.</summary>
/// <param name="lprect">
/// 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.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object, call the DeleteObject function to delete it.</para>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// <para>The region will be exclusive of the bottom and right edges.</para>
/// </remarks>
// 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);
/// <summary>The <c>CreateRoundRectRgn</c> function creates a rectangular region with rounded corners.</summary>
/// <param name="x1">Specifies the x-coordinate of the upper-left corner of the region in device units.</param>
/// <param name="y1">Specifies the y-coordinate of the upper-left corner of the region in device units.</param>
/// <param name="x2">Specifies the x-coordinate of the lower-right corner of the region in device units.</param>
/// <param name="y2">Specifies the y-coordinate of the lower-right corner of the region in device units.</param>
/// <param name="w">Specifies the width of the ellipse used to create the rounded corners in device units.</param>
/// <param name="h">Specifies the height of the ellipse used to create the rounded corners in device units.</param>
/// <returns>
/// <para>If the function succeeds, the return value is the handle to the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>When you no longer need the <c>HRGN</c> object call the DeleteObject function to delete it.</para>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// </remarks>
// 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);
/// <summary>
/// The <c>EqualRgn</c> 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.
/// </summary>
/// <param name="hrgn1">Handle to a region.</param>
/// <param name="hrgn2">Handle to a region.</param>
/// <returns>
/// <para>If the two regions are equal, the return value is nonzero.</para>
/// <para>
/// 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.
/// </para>
/// </returns>
// 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);
/// <summary>The <c>ExtCreateRegion</c> function creates a region from the specified region and transformation data.</summary>
/// <param name="lpx">
/// A pointer to an XFORM structure that defines the transformation to be performed on the region. If this pointer is <c>NULL</c>,
/// the identity transformation is used.
/// </param>
/// <param name="nCount">The number of bytes pointed to by lpRgnData.</param>
/// <param name="lpData">A pointer to a RGNDATA structure that contains the region data in logical units.</param>
/// <returns>
/// <para>If the function succeeds, the return value is the value of the region.</para>
/// <para>If the function fails, the return value is <c>NULL</c>.</para>
/// </returns>
/// <remarks>
/// <para>Region coordinates are represented as 27-bit signed integers.</para>
/// <para>An application can retrieve data for a region by calling the GetRegionData function.</para>
/// </remarks>
// 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);
/// <summary>The <c>FillRgn</c> function fills a region by using the specified brush.</summary>
/// <param name="hdc">Handle to the device context.</param>
/// <param name="hrgn">Handle to the region to be filled. The region's coordinates are presumed to be in logical units.</param>
/// <param name="hbr">Handle to the brush to be used to fill the region.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>The <c>FrameRgn</c> function draws a border around the specified region by using the specified brush.</summary>
/// <param name="hdc">Handle to the device context.</param>
/// <param name="hrgn">
/// Handle to the region to be enclosed in a border. The region's coordinates are presumed to be in logical units.
/// </param>
/// <param name="hbr">Handle to the brush to be used to draw the border.</param>
/// <param name="w">Specifies the width, in logical units, of vertical brush strokes.</param>
/// <param name="h">Specifies the height, in logical units, of horizontal brush strokes.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>The <c>GetPolyFillMode</c> function retrieves the current polygon fill mode.</summary>
/// <param name="hdc">Handle to the device context.</param>
/// <returns>
/// <para>If the function succeeds, the return value specifies the polygon fill mode, which can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ALTERNATE</term>
/// <term>Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).</term>
/// </item>
/// <item>
/// <term>WINDING</term>
/// <term>Selects winding mode (fills any region with a nonzero winding value).</term>
/// </item>
/// </list>
/// <para>If an error occurs, the return value is zero.</para>
/// </returns>
// 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 System.Drawing.Drawing2D.FillMode GetPolyFillMode(HDC hdc);
/// <summary>
/// The <c>GetRegionData</c> function fills the specified buffer with data describing a region. This data includes the dimensions of
/// the rectangles that make up the region.
/// </summary>
/// <param name="hrgn">A handle to the region.</param>
/// <param name="nCount">The size, in bytes, of the lpRgnData buffer.</param>
/// <param name="lpRgnData">
/// A pointer to a RGNDATA structure that receives the information. The dimensions of the region are in logical units. If this
/// parameter is <c>NULL</c>, the return value contains the number of bytes needed for the region data.
/// </param>
/// <returns>
/// <para>
/// 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 <c>NULL</c>, the return value is the required number of bytes.
/// </para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>The <c>GetRegionData</c> function is used in conjunction with the ExtCreateRegion function.</remarks>
// 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);
/// <summary>The <c>GetRgnBox</c> function retrieves the bounding rectangle of the specified region.</summary>
/// <param name="hrgn">A handle to the region.</param>
/// <param name="lprc">A pointer to a RECT structure that receives the bounding rectangle in logical units.</param>
/// <returns>
/// <para>The return value specifies the region's complexity. It can be one of the following values:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>NULLREGION</term>
/// <term>Region is empty.</term>
/// </item>
/// <item>
/// <term>SIMPLEREGION</term>
/// <term>Region is a single rectangle.</term>
/// </item>
/// <item>
/// <term>COMPLEXREGION</term>
/// <term>Region is more than a single rectangle.</term>
/// </item>
/// </list>
/// <para>If the hrgn parameter does not identify a valid region, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>The <c>InvertRgn</c> function inverts the colors in the specified region.</summary>
/// <param name="hdc">Handle to the device context.</param>
/// <param name="hrgn">
/// Handle to the region for which colors are inverted. The region's coordinates are presumed to be logical coordinates.
/// </param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
/// <remarks>
/// <para>
/// On monochrome screens, the <c>InvertRgn</c> 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.
/// </para>
/// <para>Examples</para>
/// <para>For an example, see Using Brushes.</para>
/// </remarks>
// 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);
/// <summary>The <c>OffsetRgn</c> function moves a region by the specified offsets.</summary>
/// <param name="hrgn">Handle to the region to be moved.</param>
/// <param name="x">Specifies the number of logical units to move left or right.</param>
/// <param name="y">Specifies the number of logical units to move up or down.</param>
/// <returns>
/// <para>The return value specifies the new region's complexity. It can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>NULLREGION</term>
/// <term>Region is empty.</term>
/// </item>
/// <item>
/// <term>SIMPLEREGION</term>
/// <term>Region is a single rectangle.</term>
/// </item>
/// <item>
/// <term>COMPLEXREGION</term>
/// <term>Region is more than one rectangle.</term>
/// </item>
/// <item>
/// <term>ERROR</term>
/// <term>An error occurred; region is unaffected.</term>
/// </item>
/// </list>
/// </returns>
// 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);
/// <summary>The <c>PaintRgn</c> function paints the specified region by using the brush currently selected into the device context.</summary>
/// <param name="hdc">Handle to the device context.</param>
/// <param name="hrgn">Handle to the region to be filled. The region's coordinates are presumed to be logical coordinates.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
/// <para>If the function fails, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>The <c>PtInRegion</c> function determines whether the specified point is inside the specified region.</summary>
/// <param name="hrgn">Handle to the region to be examined.</param>
/// <param name="x">Specifies the x-coordinate of the point in logical units.</param>
/// <param name="y">Specifies the y-coordinate of the point in logical units.</param>
/// <returns>
/// <para>If the specified point is in the region, the return value is nonzero.</para>
/// <para>If the specified point is not in the region, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>
/// The <c>RectInRegion</c> function determines whether any part of the specified rectangle is within the boundaries of a region.
/// </summary>
/// <param name="hrgn">Handle to the region.</param>
/// <param name="lprect">
/// 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.
/// </param>
/// <returns>
/// <para>If any part of the specified rectangle lies within the boundaries of the region, the return value is nonzero.</para>
/// <para>If no part of the specified rectangle lies within the boundaries of the region, the return value is zero.</para>
/// </returns>
// 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);
/// <summary>The <c>SetPolyFillMode</c> function sets the polygon fill mode for functions that fill polygons.</summary>
/// <param name="hdc">A handle to the device context.</param>
/// <param name="mode">
/// <para>The new fill mode. This parameter can be one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>ALTERNATE</term>
/// <term>Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line).</term>
/// </item>
/// <item>
/// <term>WINDING</term>
/// <term>Selects winding mode (fills any region with a nonzero winding value).</term>
/// </item>
/// </list>
/// </param>
/// <returns>The return value specifies the previous filling mode. If an error occurs, the return value is zero.</returns>
/// <remarks>
/// <para>
/// 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).
/// </para>
/// <para>
/// 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.
/// </para>
/// <para>
/// 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.
/// </para>
/// </remarks>
// 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 System.Drawing.Drawing2D.FillMode SetPolyFillMode(HDC hdc, System.Drawing.Drawing2D.FillMode mode);
/// <summary>The <c>RGNDATAHEADER</c> structure describes the data returned by the GetRegionData function.</summary>
// 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
{
/// <summary>The size, in bytes, of the header.</summary>
public uint dwSize;
/// <summary>The type of region. This value must be RDH_RECTANGLES.</summary>
public RDH iType;
/// <summary>The number of rectangles that make up the region.</summary>
public uint nCount;
/// <summary>
/// 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.
/// </summary>
public int nRgnSize;
/// <summary>A bounding rectangle for the region in logical units.</summary>
public RECT rcBound;
}
/// <summary>The <c>XFORM</c> structure specifies a world-space to page-space transformation.</summary>
/// <remarks>
/// <para>The following list describes how the members are used for each operation.</para>
/// <list type="table">
/// <listheader>
/// <term>Operation</term>
/// <term>eM11</term>
/// <term>eM12</term>
/// <term>eM21</term>
/// <term>eM22</term>
/// </listheader>
/// <item>
/// <term>Rotation</term>
/// <term>Cosine</term>
/// <term>Sine</term>
/// <term>Negative sine</term>
/// <term>Cosine</term>
/// </item>
/// <item>
/// <term>Scaling</term>
/// <term>Horizontal scaling component</term>
/// <term>Not used</term>
/// <term>Not used</term>
/// <term>Vertical Scaling Component</term>
/// </item>
/// <item>
/// <term>Shear</term>
/// <term>Not used</term>
/// <term>Horizontal Proportionality Constant</term>
/// <term>Vertical Proportionality Constant</term>
/// <term>Not used</term>
/// </item>
/// <item>
/// <term>Reflection</term>
/// <term>Horizontal Reflection Component</term>
/// <term>Not used</term>
/// <term>Not used</term>
/// <term>Vertical Reflection Component</term>
/// </item>
/// </list>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-xform typedef struct tagXFORM { FLOAT eM11; FLOAT eM12;
// FLOAT eM21; FLOAT eM22; FLOAT eDx; FLOAT eDy; } XFORM, *PXFORM, *LPXFORM;
[PInvokeData("wingdi.h", MSDNShortId = "49f0d7ee-77fa-415e-af00-b8930253a3a9")]
[StructLayout(LayoutKind.Sequential)]
public struct XFORM
{
/// <summary>
/// <para>The following.</para>
/// <list type="table">
/// <listheader>
/// <term>Operation</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>Scaling</term>
/// <term>Horizontal scaling component</term>
/// </item>
/// <item>
/// <term>Rotation</term>
/// <term>Cosine of rotation angle</term>
/// </item>
/// <item>
/// <term>Reflection</term>
/// <term>Horizontal component</term>
/// </item>
/// </list>
/// </summary>
public float eM11;
/// <summary>
/// <para>The following.</para>
/// <list type="table">
/// <listheader>
/// <term>Operation</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>Shear</term>
/// <term>Horizontal proportionality constant</term>
/// </item>
/// <item>
/// <term>Rotation</term>
/// <term>Sine of the rotation angle</term>
/// </item>
/// </list>
/// </summary>
public float eM12;
/// <summary>
/// <para>The following.</para>
/// <list type="table">
/// <listheader>
/// <term>Operation</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>Shear</term>
/// <term>Vertical proportionality constant</term>
/// </item>
/// <item>
/// <term>Rotation</term>
/// <term>Negative sine of the rotation angle</term>
/// </item>
/// </list>
/// </summary>
public float eM21;
/// <summary>
/// <para>The following.</para>
/// <list type="table">
/// <listheader>
/// <term>Operation</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>Scaling</term>
/// <term>Vertical scaling component</term>
/// </item>
/// <item>
/// <term>Rotation</term>
/// <term>Cosine of rotation angle</term>
/// </item>
/// <item>
/// <term>Reflection</term>
/// <term>Vertical reflection component</term>
/// </item>
/// </list>
/// </summary>
public float eM22;
/// <summary>The horizontal translation component, in logical units.</summary>
public float eDx;
/// <summary>The vertical translation component, in logical units.</summary>
public float eDy;
}
/// <summary>
/// The <c>RGNDATA</c> 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.
/// </summary>
// 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
{
/// <summary>
/// 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.
/// </summary>
public RGNDATAHEADER rdh;
private IntPtr _Buffer;
/// <summary>Specifies an arbitrary-size buffer that contains the RECT structures that make up the region.</summary>
public RECT[] Buffer
{
get => _Buffer.ToArray<RECT>((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;
}
}
/// <summary>Gets the size, in bytes, of the structure with allocated memory for <see cref="Buffer"/>.</summary>
public uint Size => rdh.dwSize + (uint)rdh.nRgnSize;
/// <summary>Initializes a new instance of the <see cref="RGNDATA"/> class.</summary>
/// <param name="bounds">A bounding rectangle for the region in logical units.</param>
/// <param name="count">The number of rectangles that make up the region.</param>
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;
}
/// <summary>Initializes a new instance of the <see cref="RGNDATA"/> class.</summary>
/// <param name="bounds">A bounding rectangle for the region in logical units.</param>
/// <param name="count">The RECT structures that make up the region.</param>
public RGNDATA(in RECT bounds, RECT[] rects)
{
rdh.dwSize = (uint)Marshal.SizeOf(typeof(RGNDATAHEADER));
rdh.iType = RDH.RDH_RECTANGLES;
Buffer = rects;
rdh.rcBound = bounds;
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose() { Marshal.FreeHGlobal(_Buffer); _Buffer = IntPtr.Zero; }
}
}
}