From 70b0cf4393b03df3c27134c5525d1045a2ef619f Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 11 Jun 2019 13:37:18 -0600 Subject: [PATCH] Added color, OpenGL and region functions to Gdi32 --- PInvoke/Gdi32/WinGdi.Color.cs | 855 +++++++++++++++++++++++++++++++++++++++++ PInvoke/Gdi32/WinGdi.OpenGL.cs | 656 +++++++++++++++++++++++++++++++ PInvoke/Gdi32/WinGdi.Region.cs | 841 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2352 insertions(+) create mode 100644 PInvoke/Gdi32/WinGdi.Color.cs create mode 100644 PInvoke/Gdi32/WinGdi.OpenGL.cs create mode 100644 PInvoke/Gdi32/WinGdi.Region.cs diff --git a/PInvoke/Gdi32/WinGdi.Color.cs b/PInvoke/Gdi32/WinGdi.Color.cs new file mode 100644 index 00000000..698bd75b --- /dev/null +++ b/PInvoke/Gdi32/WinGdi.Color.cs @@ -0,0 +1,855 @@ +using System; +using System.Runtime.InteropServices; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class Gdi32 + { + /// Specifies how the output image should be prepared. + [PInvokeData("wingdi.h", MSDNShortId = "9a080f60-0bce-46b6-b8a8-f534ff83a0a8")] + public enum CA_FLAGS : ushort + { + /// Specifies that the negative of the original image should be displayed. + CA_NEGATIVE = 0x0001, + + /// + /// 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. + /// + CA_LOG_FILTER = 0x0002, + } + + /// The type of standard light source under which the image is viewed. + [PInvokeData("wingdi.h", MSDNShortId = "9a080f60-0bce-46b6-b8a8-f534ff83a0a8")] + public enum ILLUMINANT : ushort + { + /// Device's default. Standard used by output devices. + ILLUMINANT_DEVICE_DEFAULT = 0, + + /// Tungsten lamp. + ILLUMINANT_A = 1, + + /// Noon sunlight. + ILLUMINANT_B = 2, + + /// NTSC daylight. + ILLUMINANT_C = 3, + + /// Normal print. + ILLUMINANT_D50 = 4, + + /// Bond paper print. + ILLUMINANT_D55 = 5, + + /// Standard daylight. Standard for CRTs and pictures. + ILLUMINANT_D65 = 6, + + /// Northern daylight. + ILLUMINANT_D75 = 7, + + /// Cool white lamp. + ILLUMINANT_F2 = 8, + + /// Same as ILLUMINANT_A. + ILLUMINANT_TUNGSTEN = ILLUMINANT_A, + + /// Same as ILLUMINANT_C. + ILLUMINANT_DAYLIGHT = ILLUMINANT_C, + + /// Same as ILLUMINANT_F2. + ILLUMINANT_FLUORESCENT = ILLUMINANT_F2, + + /// Same as ILLUMINANT_C. + ILLUMINANT_NTSC = ILLUMINANT_C, + } + + /// The alpha intensity value for the palette entry. + [PInvokeData("wingdi.h")] + public enum PC : byte + { + /// + /// 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. + /// + PC_EXPLICIT = 0x2, + + /// + /// 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. + /// + PC_NOCOLLAPSE = 0x4, + + /// + /// 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. + /// + PC_RESERVED = 0x1, + } + + /// The current state of the system (physical) palette. + [PInvokeData("wingdi.h", MSDNShortId = "0a9e7906-2f81-4fda-b03d-86feb0755327")] + public enum SYSPAL + { + /// The given device context is invalid or does not support a color palette. + SYSPAL_ERROR = 0, + + /// The system palette contains static colors that will not change when an application realizes its logical palette. + SYSPAL_STATIC = 1, + + /// The system palette contains no static colors except black and white. + SYSPAL_NOSTATIC = 2, + + /// The system palette contains no static colors. + SYSPAL_NOSTATIC256 = 3, + } + + /// The AnimatePalette function replaces entries in the specified logical palette. + /// A handle to the logical palette. + /// The first logical palette entry to be replaced. + /// The number of entries to be replaced. + /// A pointer to the first member in an array of PALETTEENTRY structures used to replace the current entries. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// The AnimatePalette function only changes entries with the PC_RESERVED flag set in the corresponding palPalEntry + /// member of the LOGPALETTE structure. + /// + /// If the given palette is associated with the active window, the colors in the palette are replaced immediately. + /// + // 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); + + /// The CreateHalftonePalette function creates a halftone palette for the specified device context (DC). + /// A handle to the device context. + /// + /// If the function succeeds, the return value is a handle to a logical halftone palette. + /// If the function fails, the return value is zero. + /// + /// + /// + /// 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 CreateHalftonePalette should then be selected and realized into the device context before the + /// StretchBlt or StretchDIBits function is called. + /// + /// When you no longer need the palette, call the DeleteObject function to delete it. + /// + // 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); + + /// The CreatePalette function creates a logical palette. + /// A pointer to a LOGPALETTE structure that contains information about the colors in the logical palette. + /// + /// If the function succeeds, the return value is a handle to a logical palette. + /// If the function fails, the return value is NULL. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// 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. + /// + /// When you no longer need the palette, call the DeleteObject function to delete it. + /// + // 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); + + /// The GetColorAdjustment function retrieves the color adjustment values for the specified device context (DC). + /// A handle to the device context. + /// A pointer to a COLORADJUSTMENT structure that receives the color adjustment values. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-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); + + /// + /// The GetNearestColor function retrieves a color value identifying a color from the system palette that will be displayed + /// when the specified color value is used. + /// + /// A handle to the device context. + /// A color value that identifies a requested color. To create a COLORREF color value, use the RGB macro. + /// + /// + /// If the function succeeds, the return value identifies a color from the system palette that corresponds to the given color value. + /// + /// If the function fails, the return value is CLR_INVALID. + /// + // 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); + + /// + /// The GetNearestPaletteIndex function retrieves the index for the entry in the specified logical palette most closely + /// matching a specified color value. + /// + /// + /// If the function succeeds, the return value is the index of an entry in a logical palette. + /// If the function fails, the return value is CLR_INVALID. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and + /// specifying the RASTERCAPS constant. + /// + /// If the given logical palette contains entries with the PC_EXPLICIT flag set, the return value is undefined. + /// + // 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); + + /// The GetPaletteEntries function retrieves a specified range of palette entries from the given logical palette. + /// A handle to the logical palette. + /// The first entry in the logical palette to be retrieved. + /// The number of entries in the logical palette to be retrieved. + /// + /// 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 the function succeeds and the handle to the logical palette is a valid pointer (not NULL), the return value is the + /// number of entries retrieved from the logical palette. If the function succeeds and handle to the logical palette is NULL, + /// the return value is the number of entries in the given palette. + /// + /// If the function fails, the return value is zero. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// If the nEntries parameter specifies more entries than exist in the palette, the remaining members of the PALETTEENTRY structure + /// are not altered. + /// + /// + // 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); + + /// + /// The GetSystemPaletteEntries function retrieves a range of palette entries from the system palette that is associated with + /// the specified device context (DC). + /// + /// A handle to the device context. + /// The first entry to be retrieved from the system palette. + /// The number of entries to be retrieved from the system palette. + /// + /// 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 NULL, the function returns the total number of + /// entries in the palette. + /// + /// + /// If the function succeeds, the return value is the number of entries retrieved from the palette. + /// If the function fails, the return value is zero. + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + // 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); + + /// + /// The GetSystemPaletteUse function retrieves the current state of the system (physical) palette for the specified device + /// context (DC). + /// + /// A handle to the device context. + /// + /// + /// If the function succeeds, the return value is the current state of the system palette. This parameter can be one of the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// SYSPAL_NOSTATIC + /// The system palette contains no static colors except black and white. + /// + /// + /// SYSPAL_STATIC + /// The system palette contains static colors that will not change when an application realizes its logical palette. + /// + /// + /// SYSPAL_ERROR + /// The given device context is invalid or does not support a color palette. + /// + /// + /// + /// + /// + /// 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. + /// + /// The device context identified by the hdc parameter must represent a device that supports color palettes. + /// + /// An application can determine whether a device supports color palettes by calling the GetDeviceCaps function and specifying the + /// RASTERCAPS constant. + /// + /// + // 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); + + /// The RealizePalette function maps palette entries from the current logical palette to the system palette. + /// A handle to the device context into which a logical palette has been selected. + /// + /// If the function succeeds, the return value is the number of entries in the logical palette mapped to the system palette. + /// If the function fails, the return value is GDI_ERROR. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// The RealizePalette 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. + /// + /// + /// 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. + /// + /// + /// When an application's window has the focus and it calls the RealizePalette function, the system attempts to realize as + /// many of the requested colors as possible. The same is also true for applications with inactive windows. + /// + /// + // 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); + + /// The ResizePalette function increases or decreases the size of a logical palette based on the specified value. + /// A handle to the palette to be changed. + /// + /// The number of entries in the palette after it has been resized. + /// The number of entries is limited to 1024. + /// + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// If an application calls ResizePalette to reduce the size of the palette, the entries remaining in the resized palette are + /// unchanged. If the application calls ResizePalette 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. + /// + /// + // 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); + + /// The SelectPalette function selects the specified logical palette into a device context. + /// A handle to the device context. + /// A handle to the logical palette to be selected. + /// + /// + /// Specifies whether the logical palette is forced to be a background palette. If this value is TRUE, 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. + /// + /// + /// If this value is FALSE, 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.) + /// + /// + /// + /// If the function succeeds, the return value is a handle to the device context's previous logical palette. + /// If the function fails, the return value is NULL. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// An application can select a logical palette into more than one device context only if device contexts are compatible. Otherwise + /// SelectPalette 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. + /// + /// + /// An application might call the SelectPalette function with the bForceBackground parameter set to TRUE 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 TRUE; other child windows must set this value to FALSE. + /// + /// + // 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); + + /// + /// The SetColorAdjustment function sets the color adjustment values for a device context (DC) using the specified values. + /// + /// A handle to the device context. + /// A pointer to a COLORADJUSTMENT structure containing the color adjustment values. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// 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. + /// + // 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); + + /// + /// The SetPaletteEntries function sets RGB (red, green, blue) color values and flags in a range of entries in a logical palette. + /// + /// A handle to the logical palette. + /// The first logical-palette entry to be set. + /// The number of logical-palette entries to be set. + /// + /// A pointer to the first member of an array of PALETTEENTRY structures containing the RGB values and flags. + /// + /// + /// If the function succeeds, the return value is the number of entries that were set in the logical palette. + /// If the function fails, the return value is zero. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// 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. + /// + /// + // 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); + + /// + /// The SetSystemPaletteUse 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.) + /// + /// A handle to the device context. This device context must refer to a device that supports color palettes. + /// + /// The new use of the system palette. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// SYSPAL_NOSTATIC + /// The system palette contains two static colors (black and white). + /// + /// + /// SYSPAL_NOSTATIC256 + /// The system palette contains no static colors. + /// + /// + /// SYSPAL_STATIC + /// The system palette contains static colors that will not change when an application realizes its logical palette. + /// + /// + /// + /// + /// + /// If the function succeeds, the return value is the previous system palette. It can be either SYSPAL_NOSTATIC, SYSPAL_NOSTATIC256, + /// or SYSPAL_STATIC. + /// + /// If the function fails, the return value is SYSPAL_ERROR. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// 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. + /// + /// If the function returns SYSPAL_ERROR, the specified device context is invalid or does not support color palettes. + /// An application must call this function only when its window is maximized and has the input focus. + /// + /// If an application calls SetSystemPaletteUse 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. + /// + /// After calling this function with uUsage set to SYSPAL_NOSTATIC, an application must take the following steps: + /// + /// + /// Realize the logical palette. + /// + /// + /// Call the GetSysColor function to save the current system-color settings. + /// + /// + /// + /// 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. + /// + /// + /// + /// Send the WM_SYSCOLORCHANGE message to other top-level windows to allow them to be redrawn with the new system colors. + /// + /// + /// When the application's window loses focus or closes, the application must perform the following steps: + /// + /// + /// Call SetSystemPaletteUse with the uUsage parameter set to SYSPAL_STATIC. + /// + /// + /// Realize the logical palette. + /// + /// + /// Restore the system colors to their previous values. + /// + /// + /// Send the WM_SYSCOLORCHANGE message. + /// + /// + /// + // 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); + + /// + /// The UnrealizeObject function resets the origin of a brush or resets a logical palette. If the hgdiobj parameter is a + /// handle to a brush, UnrealizeObject 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, UnrealizeObject 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. + /// + /// A handle to the logical palette to be reset. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// + /// The UnrealizeObject function should not be used with stock objects. For example, the default palette, obtained by calling + /// GetStockObject (DEFAULT_PALETTE), is a stock object. + /// + /// A palette identified by hgdiobj can be the currently selected palette of a device context. + /// + /// If hgdiobj is a brush, UnrealizeObject does nothing, and the function returns TRUE. Use SetBrushOrgEx to set the + /// origin of a brush. + /// + /// + // 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); + + /// + /// The UpdateColors 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. + /// + /// A handle to the device context. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// + /// An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying + /// the RASTERCAPS constant. + /// + /// + /// An inactive window with a realized logical palette may call UpdateColors as an alternative to redrawing its client area + /// when the system palette changes. + /// + /// + /// The UpdateColors function typically updates a client area faster than redrawing the area. However, because + /// UpdateColors 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. + /// + /// This function must be called soon after a WM_PALETTECHANGED message is received. + /// + // 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); + + /// + /// The COLORADJUSTMENT 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. + /// + // 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 + { + /// The size, in bytes, of the structure. + public ushort caSize; + + /// + /// + /// Specifies how the output image should be prepared. This member may be set to NULL or any combination of the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// CA_NEGATIVE + /// Specifies that the negative of the original image should be displayed. + /// + /// + /// CA_LOG_FILTER + /// + /// 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. + /// + /// + /// + /// + public CA_FLAGS caFlags; + + /// + /// + /// The type of standard light source under which the image is viewed. This member may be set to one of the following values. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// ILLUMINANT_DEVICE_DEFAULT + /// Device's default. Standard used by output devices. + /// + /// + /// ILLUMINANT_A + /// Tungsten lamp. + /// + /// + /// ILLUMINANT_B + /// Noon sunlight. + /// + /// + /// ILLUMINANT_C + /// NTSC daylight. + /// + /// + /// ILLUMINANT_D50 + /// Normal print. + /// + /// + /// ILLUMINANT_D55 + /// Bond paper print. + /// + /// + /// ILLUMINANT_D65 + /// Standard daylight. Standard for CRTs and pictures. + /// + /// + /// ILLUMINANT_D75 + /// Northern daylight. + /// + /// + /// ILLUMINANT_F2 + /// Cool white lamp. + /// + /// + /// ILLUMINANT_TUNGSTEN + /// Same as ILLUMINANT_A. + /// + /// + /// ILLUMINANT_DAYLIGHT + /// Same as ILLUMINANT_C. + /// + /// + /// ILLUMINANT_FLUORESCENT + /// Same as ILLUMINANT_F2. + /// + /// + /// ILLUMINANT_NTSC + /// Same as ILLUMINANT_C. + /// + /// + /// + public ILLUMINANT caIlluminantIndex; + + /// + /// 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. + /// + public ushort caRedGamma; + + /// + /// 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. + /// + public ushort caGreenGamma; + + /// + /// 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. + /// + public ushort caBlueGamma; + + /// + /// 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. + /// + public ushort caReferenceBlack; + + /// + /// 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. + /// + public ushort caReferenceWhite; + + /// + /// 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. + /// + public short caContrast; + + /// + /// 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. + /// + public short caBrightness; + + /// + /// 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. + /// + public short caColorfulness; + + /// + /// 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. + /// + public short caRedGreenTint; + } + + /// Specifies the color and usage of an entry in a logical palette. + // 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 + { + /// + /// Type: BYTE + /// The red intensity value for the palette entry. + /// + public byte peRed; + + /// + /// Type: BYTE + /// The green intensity value for the palette entry. + /// + public byte peGreen; + + /// + /// Type: BYTE + /// The blue intensity value for the palette entry. + /// + public byte peBlue; + + /// + /// Type: BYTE + /// + /// The alpha intensity value for the palette entry. Note that as of DirectX 8, this member is treated differently than + /// documented for Windows. + /// + /// + public PC peFlags; + } + + /// The LOGPALETTE structure defines a logical palette. + /// + /// 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. + /// + // 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 + { + /// The version number of the system. + public ushort palVersion; + + /// The number of entries in the logical palette. + public ushort palNumEntries; + + private IntPtr _palPalEntry; + + /// Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette. + public PALETTEENTRY[] palPalEntry + { + get => _palPalEntry.ToArray(palNumEntries); + set { Marshal.FreeHGlobal(_palPalEntry); value.MarshalToPtr(Marshal.AllocHGlobal, out _); } + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry); + } + } +} \ No newline at end of file diff --git a/PInvoke/Gdi32/WinGdi.OpenGL.cs b/PInvoke/Gdi32/WinGdi.OpenGL.cs new file mode 100644 index 00000000..a2a97cca --- /dev/null +++ b/PInvoke/Gdi32/WinGdi.OpenGL.cs @@ -0,0 +1,656 @@ +using System; +using System.Runtime.InteropServices; + +namespace Vanara.PInvoke +{ + public static partial class Gdi32 + { + /// A set of bit flags that specify properties of the pixel buffer. + [PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")] + [Flags] + public enum PFD_FLAGS : uint + { + /// The buffer is double-buffered. This flag and PFD_SUPPORT_GDI are mutually exclusive in the current generic implementation. + PFD_DOUBLEBUFFER = 0x00000001, + + /// The buffer is stereoscopic. This flag is not supported in the current generic implementation. + PFD_STEREO = 0x00000002, + + /// The buffer can draw to a window or device surface. + PFD_DRAW_TO_WINDOW = 0x00000004, + + /// The buffer can draw to a memory bitmap. + PFD_DRAW_TO_BITMAP = 0x00000008, + + /// + /// The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER are mutually exclusive in the current generic implementation. + /// + PFD_SUPPORT_GDI = 0x00000010, + + /// The buffer supports OpenGL drawing. + PFD_SUPPORT_OPENGL = 0x00000020, + + /// + /// 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. + /// + PFD_GENERIC_FORMAT = 0x00000040, + + /// + /// 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. + /// + PFD_NEED_PALETTE = 0x00000080, + + /// + /// 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. + /// + PFD_NEED_SYSTEM_PALETTE = 0x00000100, + + /// + /// 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. + /// + PFD_SWAP_EXCHANGE = 0x00000200, + + /// + /// 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. + /// + PFD_SWAP_COPY = 0x00000400, + + /// + /// 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. + /// + PFD_SWAP_LAYER_BUFFERS = 0x00000800, + + /// + /// 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. + /// + PFD_GENERIC_ACCELERATED = 0x00001000, + + /// The PFD support directdraw + PFD_SUPPORT_DIRECTDRAW = 0x00002000, + + /// The PFD direc t3 d accelerated + PFD_DIRECT3D_ACCELERATED = 0x00004000, + + /// The PFD support composition + PFD_SUPPORT_COMPOSITION = 0x00008000, + + /// + /// 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. + /// + PFD_DEPTH_DONTCARE = 0x20000000, + + /// The requested pixel format can be either single- or double-buffered. + PFD_DOUBLEBUFFER_DONTCARE = 0x40000000, + + /// The requested pixel format can be either monoscopic or stereoscopic. + PFD_STEREO_DONTCARE = 0x80000000, + } + + /// The plane layer. + [PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")] + public enum PFD_LAYER : sbyte + { + /// The layer is the main plane. + PFD_MAIN_PLANE = 0, + + /// The layer is the overlay plane. + PFD_OVERLAY_PLANE = 1, + + /// The layer is the underlay plane. + PFD_UNDERLAY_PLANE = -1 + } + + /// Specifies the type of pixel data. + [PInvokeData("wingdi.h", MSDNShortId = "1480dea3-ae74-4e8b-b4de-fca8de5d8395")] + public enum PFD_TYPE : byte + { + /// RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha. + PFD_TYPE_RGBA = 0, + + /// Color-index pixels. Each pixel uses a color-index value. + PFD_TYPE_COLORINDEX = 1, + } + + /// + /// The ChoosePixelFormat function attempts to match an appropriate pixel format supported by a device context to a given + /// pixel format specification. + /// + /// + /// Specifies the device context that the function examines to determine the best match for the pixel format descriptor pointed to by ppfd. + /// + /// + /// + /// Pointer to a PIXELFORMATDESCRIPTOR structure that specifies the requested pixel format. In this context, the members of the + /// PIXELFORMATDESCRIPTOR structure that ppfd points to are used as follows: + /// + /// + /// + /// nSize + /// Specifies the size of the PIXELFORMATDESCRIPTOR data structure. Set this member to . + /// + /// + /// nVersion + /// Specifies the version number of the PIXELFORMATDESCRIPTOR data structure. Set this member to 1. + /// + /// + /// dwFlags + /// + /// 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 + /// + /// + /// + /// iPixelType + /// Specifies the type of pixel format for the function to consider: PFD_TYPE_RGBA, PFD_TYPE_COLORINDEX + /// + /// + /// cColorBits + /// Zero or greater. + /// + /// + /// cRedBits + /// Not used. + /// + /// + /// cRedShift + /// Not used. + /// + /// + /// cGreenBits + /// Not used. + /// + /// + /// cGreenShift + /// Not used. + /// + /// + /// cBlueBits + /// Not used. + /// + /// + /// cBlueShift + /// Not used. + /// + /// + /// cAlphaBits + /// Zero or greater. + /// + /// + /// cAlphaShift + /// Not used. + /// + /// + /// cAccumBits + /// Zero or greater. + /// + /// + /// cAccumRedBits + /// Not used. + /// + /// + /// cAccumGreenBits + /// Not used. + /// + /// + /// cAccumBlueBits + /// Not used. + /// + /// + /// cAccumAlphaBits + /// Not used. + /// + /// + /// cDepthBits + /// Zero or greater. + /// + /// + /// cStencilBits + /// Zero or greater. + /// + /// + /// cAuxBuffers + /// Zero or greater. + /// + /// + /// iLayerType + /// Specifies one of the following layer type values: PFD_MAIN_PLANE, PFD_OVERLAY_PLANE, PFD_UNDERLAY_PLANE + /// + /// + /// bReserved + /// Not used. + /// + /// + /// dwLayerMask + /// Not used. + /// + /// + /// dwVisibleMask + /// Not used. + /// + /// + /// dwDamageMask + /// Not used. + /// + /// + /// + /// + /// + /// 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. + /// + /// If the function fails, the return value is zero. To get extended error information, call GetLastError. + /// + /// + /// + /// You must ensure that the pixel format matched by the ChoosePixelFormat 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. + /// + /// Examples + /// The following code sample shows how to use ChoosePixelFormat to match a specified pixel format. + /// + // 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); + + /// + /// The DescribePixelFormat 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. + /// + /// Specifies the device context. + /// + /// Index that specifies the pixel format. The pixel formats that a device context supports are identified by positive one-based + /// integer indexes. + /// + /// + /// The size, in bytes, of the structure pointed to by ppfd. The DescribePixelFormat function stores no more than nBytes bytes + /// of data to that structure. Set this value to sizeof( PIXELFORMATDESCRIPTOR). + /// + /// + /// Pointer to a PIXELFORMATDESCRIPTOR 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 nSize member. If, upon entry, ppfd is NULL, 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. + /// + /// + /// + /// 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 PIXELFORMATDESCRIPTOR structure pointed to by ppfd according to the specified pixel format. + /// + /// If the function fails, the return value is zero. To get extended error information, call GetLastError. + /// + // 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); + + /// The GetEnhMetaFilePixelFormat function retrieves pixel format information for an enhanced metafile. + /// Identifies the enhanced metafile. + /// Specifies the size, in bytes, of the buffer into which the pixel format information is copied. + /// + /// Pointer to a PIXELFORMATDESCRIPTOR structure that contains the logical pixel format specification. The metafile uses this + /// structure to record the logical pixel format specification. + /// + /// + /// If the function succeeds and finds a pixel format, the return value is the size of the metafile's pixel format. + /// If no pixel format is present, the return value is zero. + /// If an error occurs and the function fails, the return value is GDI_ERROR. To get extended error information, call GetLastError. + /// + /// + /// + /// When an enhanced metafile specifies a pixel format in its ENHMETAHEADER 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. + /// + /// For information on metafile recording and other operations, see Enhanced Metafile Operations. + /// + // 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); + + /// + /// The SetPixelFormat function sets the pixel format of the specified device context to the format specified by the + /// iPixelFormat index. + /// + /// Specifies the device context whose pixel format the function attempts to set. + /// + /// Index that identifies the pixel format to set. The various pixel formats supported by a device context are identified by + /// one-based indexes. + /// + /// + /// 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 SetPixelFormat function. + /// + /// + /// If the function succeeds, the return value is TRUE. + /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. + /// + /// + /// + /// If hdc references a window, calling the SetPixelFormat 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. + /// + /// + /// You should select a pixel format in the device context before calling the wglCreateContext function. The wglCreateContext + /// function creates a rendering context for drawing on the device in the selected pixel format of the device context. + /// + /// + /// 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. + /// + /// Examples + /// The following code example shows SetPixelFormat usage. + /// + // 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); + + /// + /// The SwapBuffers 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. + /// + /// + /// 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. + /// + /// + /// If the function succeeds, the return value is TRUE. + /// If the function fails, the return value is FALSE. To get extended error information, call GetLastError. + /// + /// + /// + /// 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. + /// + /// + /// With multithread applications, flush the drawing commands in any other threads drawing to the same window before calling SwapBuffers. + /// + /// + // 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); + + /// The PIXELFORMATDESCRIPTOR structure describes the pixel format of a drawing surface. + /// + /// 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. + /// + // 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 + { + /// Specifies the size of this data structure. This value should be set to sizeof( PIXELFORMATDESCRIPTOR). + public ushort nSize; + + /// Specifies the version of this data structure. This value should be set to 1. + public ushort nVersion; + + /// + /// + /// 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. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// PFD_DRAW_TO_WINDOW + /// The buffer can draw to a window or device surface. + /// + /// + /// PFD_DRAW_TO_BITMAP + /// The buffer can draw to a memory bitmap. + /// + /// + /// PFD_SUPPORT_GDI + /// The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER are mutually exclusive in the current generic implementation. + /// + /// + /// PFD_SUPPORT_OPENGL + /// The buffer supports OpenGL drawing. + /// + /// + /// PFD_GENERIC_ACCELERATED + /// + /// 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. + /// + /// + /// + /// PFD_GENERIC_FORMAT + /// + /// 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. + /// + /// + /// + /// PFD_NEED_PALETTE + /// + /// 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. + /// + /// + /// + /// PFD_NEED_SYSTEM_PALETTE + /// + /// 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. + /// + /// + /// + /// PFD_DOUBLEBUFFER + /// The buffer is double-buffered. This flag and PFD_SUPPORT_GDI are mutually exclusive in the current generic implementation. + /// + /// + /// PFD_STEREO + /// The buffer is stereoscopic. This flag is not supported in the current generic implementation. + /// + /// + /// PFD_SWAP_LAYER_BUFFERS + /// + /// 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. + /// + /// + /// + /// You can specify the following bit flags when calling ChoosePixelFormat. + /// + /// + /// Value + /// Meaning + /// + /// + /// PFD_DEPTH_DONTCARE + /// + /// 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. + /// + /// + /// + /// PFD_DOUBLEBUFFER_DONTCARE + /// The requested pixel format can be either single- or double-buffered. + /// + /// + /// PFD_STEREO_DONTCARE + /// The requested pixel format can be either monoscopic or stereoscopic. + /// + /// + /// + /// With the glAddSwapHintRectWIN extension function, two new flags are included for the PIXELFORMATDESCRIPTOR + /// pixel format structure. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// PFD_SWAP_COPY + /// + /// 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. + /// + /// + /// + /// PFD_SWAP_EXCHANGE + /// + /// 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. + /// + /// + /// + /// + public PFD_FLAGS dwFlags; + + /// + /// Specifies the type of pixel data. The following types are defined. + /// + /// + /// Value + /// Meaning + /// + /// + /// PFD_TYPE_RGBA + /// RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha. + /// + /// + /// PFD_TYPE_COLORINDEX + /// Color-index pixels. Each pixel uses a color-index value. + /// + /// + /// + public PFD_TYPE iPixelType; + + /// + /// 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. + /// + public byte cColorBits; + + /// Specifies the number of red bitplanes in each RGBA color buffer. + public byte cRedBits; + + /// Specifies the shift count for red bitplanes in each RGBA color buffer. + public byte cRedShift; + + /// Specifies the number of green bitplanes in each RGBA color buffer. + public byte cGreenBits; + + /// Specifies the shift count for green bitplanes in each RGBA color buffer. + public byte cGreenShift; + + /// Specifies the number of blue bitplanes in each RGBA color buffer. + public byte cBlueBits; + + /// Specifies the shift count for blue bitplanes in each RGBA color buffer. + public byte cBlueShift; + + /// Specifies the number of alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported. + public byte cAlphaBits; + + /// Specifies the shift count for alpha bitplanes in each RGBA color buffer. Alpha bitplanes are not supported. + public byte cAlphaShift; + + /// Specifies the total number of bitplanes in the accumulation buffer. + public byte cAccumBits; + + /// Specifies the number of red bitplanes in the accumulation buffer. + public byte cAccumRedBits; + + /// Specifies the number of green bitplanes in the accumulation buffer. + public byte cAccumGreenBits; + + /// Specifies the number of blue bitplanes in the accumulation buffer. + public byte cAccumBlueBits; + + /// Specifies the number of alpha bitplanes in the accumulation buffer. + public byte cAccumAlphaBits; + + /// Specifies the depth of the depth (z-axis) buffer. + public byte cDepthBits; + + /// Specifies the depth of the stencil buffer. + public byte cStencilBits; + + /// Specifies the number of auxiliary buffers. Auxiliary buffers are not supported. + public byte cAuxBuffers; + + /// Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. + public byte iLayerType; + + /// + /// 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. + /// + public byte bReserved; + + /// Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. + public PFD_LAYER dwLayerMask; + + /// + /// Specifies the transparent color or index of an underlay plane. When the pixel type is RGBA, dwVisibleMask is a + /// transparent RGB color value. When the pixel type is color index, it is a transparent index value. + /// + public uint dwVisibleMask; + + /// Ignored. Earlier implementations of OpenGL used this member, but it is no longer used. + public uint dwDamageMask; + } + } +} \ No newline at end of file diff --git a/PInvoke/Gdi32/WinGdi.Region.cs b/PInvoke/Gdi32/WinGdi.Region.cs new file mode 100644 index 00000000..30b595bf --- /dev/null +++ b/PInvoke/Gdi32/WinGdi.Region.cs @@ -0,0 +1,841 @@ +using System; +using System.Runtime.InteropServices; +using Vanara.Extensions; + +namespace Vanara.PInvoke +{ + public static partial class Gdi32 + { + /// The type of region. + [PInvokeData("wingdi.h", MSDNShortId = "15990903-8a48-4c47-b527-269d775255a5")] + public enum RDH + { + /// Rectangle region type. + RDH_RECTANGLES = 1 + } + + /// A mode indicating how the two regions will be combined. + [PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")] + public enum RGN_COMB + { + /// Creates the intersection of the two combined regions. + RGN_AND = 1, + + /// Creates the union of two combined regions. + RGN_OR = 2, + + /// Creates the union of two combined regions except for any overlapping areas. + RGN_XOR = 3, + + /// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. + RGN_DIFF = 4, + + /// Creates a copy of the region identified by hrgnSrc1. + RGN_COPY = 5, + } + + /// The type of the resulting region. + [PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")] + public enum RGN_TYPE + { + /// No region is created. + ERROR = 0, + + /// The region is empty. + NULLREGION = 1, + + /// The region is a single rectangle. + SIMPLEREGION = 2, + + /// The region is more than a single rectangle. + COMPLEXREGION = 3, + } + + /// + /// The CombineRgn function combines two regions and stores the result in a third region. The two regions are combined + /// according to the specified mode. + /// + /// + /// A handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn + /// is called.) + /// + /// A handle to the first of two regions to be combined. + /// A handle to the second of two regions to be combined. + /// + /// A mode indicating how the two regions will be combined. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// RGN_AND + /// Creates the intersection of the two combined regions. + /// + /// + /// RGN_COPY + /// Creates a copy of the region identified by hrgnSrc1. + /// + /// + /// RGN_DIFF + /// Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. + /// + /// + /// RGN_OR + /// Creates the union of two combined regions. + /// + /// + /// RGN_XOR + /// Creates the union of two combined regions except for any overlapping areas. + /// + /// + /// + /// + /// The return value specifies the type of the resulting region. It can be one of the following values. + /// + /// + /// Return code + /// Description + /// + /// + /// NULLREGION + /// The region is empty. + /// + /// + /// SIMPLEREGION + /// The region is a single rectangle. + /// + /// + /// COMPLEXREGION + /// The region is more than a single rectangle. + /// + /// + /// ERROR + /// No region is created. + /// + /// + /// + /// The three regions need not be distinct. For example, the hrgnSrc1 parameter can equal the hrgnDest parameter. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-combinergn int CombineRgn( HRGN hrgnDst, HRGN hrgnSrc1, HRGN + // hrgnSrc2, int iMode ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "ef9fc4f3-737e-4c10-a80b-8ae2097c17d1")] + public static extern RGN_TYPE CombineRgn(HRGN hrgnDst, HRGN hrgnSrc1, HRGN hrgnSrc2, RGN_COMB iMode); + + /// The CreateEllipticRgn function creates an elliptical region. + /// Specifies the x-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse. + /// Specifies the y-coordinate in logical units, of the upper-left corner of the bounding rectangle of the ellipse. + /// Specifies the x-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse. + /// Specifies the y-coordinate in logical units, of the lower-right corner of the bounding rectangle of the ellipse. + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// + /// A bounding rectangle defines the size, shape, and orientation of the region: The long sides of the rectangle define the length of + /// the ellipse's major axis; the short sides define the length of the ellipse's minor axis; and the center of the rectangle defines + /// the intersection of the major and minor axes. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createellipticrgn HRGN CreateEllipticRgn( int x1, int y1, + // int x2, int y2 ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "b4e9b210-8e22-42db-bb6e-65f1fb870eff")] + public static extern SafeHRGN CreateEllipticRgn(int x1, int y1, int x2, int y2); + + /// The CreateEllipticRgnIndirect function creates an elliptical region. + /// + /// Pointer to a RECT structure that contains the coordinates of the upper-left and lower-right corners of the bounding rectangle of + /// the ellipse in logical units. + /// + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// + /// A bounding rectangle defines the size, shape, and orientation of the region: The long sides of the rectangle define the length of + /// the ellipse's major axis; the short sides define the length of the ellipse's minor axis; and the center of the rectangle defines + /// the intersection of the major and minor axes. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createellipticrgnindirect HRGN CreateEllipticRgnIndirect( + // const RECT *lprect ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "bd30516e-1e05-4b7d-a6bf-7512cf3ef30f")] + public static extern SafeHRGN CreateEllipticRgnIndirect(in RECT lprect); + + /// The CreatePolygonRgn function creates a polygonal region. + /// + /// A pointer to an array of POINT structures that define the vertices of the polygon in logical units. The polygon is presumed + /// closed. Each vertex can be specified only once. + /// + /// The number of points in the array. + /// + /// The fill mode used to determine which pixels are in the region. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// ALTERNATE + /// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line). + /// + /// + /// WINDING + /// Selects winding mode (fills any region with a nonzero winding value). + /// + /// + /// For more information about these modes, see the SetPolyFillMode function. + /// + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// Region coordinates are represented as 27-bit signed integers. + /// + /// Regions created by the Create<shape>Rgn methods (such as CreateRectRgn and CreatePolygonRgn) only include the + /// interior of the shape; the shape's outline is excluded from the region. This means that any point on a line between two + /// sequential vertices is not included in the region. If you were to call PtInRegion for such a point, it would return zero as the result. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpolygonrgn HRGN CreatePolygonRgn( const POINT *pptl, + // int cPoint, int iMode ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "dd7ad6de-c5f2-46e4-8d28-24caaa48ba3a")] + public static extern SafeHRGN CreatePolygonRgn(System.Drawing.Point pptl, int cPoint, System.Drawing.Drawing2D.FillMode iMode); + + /// The CreatePolyPolygonRgn function creates a region consisting of a series of polygons. The polygons can overlap. + /// + /// A pointer to an array of POINT structures that define the vertices of the polygons in logical units. The polygons are specified + /// consecutively. Each polygon is presumed closed and each vertex is specified only once. + /// + /// + /// A pointer to an array of integers, each of which specifies the number of points in one of the polygons in the array pointed to by lppt. + /// + /// The total number of integers in the array pointed to by lpPolyCounts. + /// + /// The fill mode used to determine which pixels are in the region. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// ALTERNATE + /// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line). + /// + /// + /// WINDING + /// Selects winding mode (fills any region with a nonzero winding value). + /// + /// + /// For more information about these modes, see the SetPolyFillMode function. + /// + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is zero. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// Region coordinates are represented as 27-bit signed integers. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpolypolygonrgn HRGN CreatePolyPolygonRgn( const POINT + // *pptl, const INT *pc, int cPoly, int iMode ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "1113d3dc-8e3f-436c-a5a8-191785bc7fcc")] + public static extern SafeHRGN CreatePolyPolygonRgn([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] System.Drawing.Point[] pptl, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] int[] pc, int cPoly, System.Drawing.Drawing2D.FillMode iMode); + + /// The CreateRectRgn function creates a rectangular region. + /// Specifies the x-coordinate of the upper-left corner of the region in logical units. + /// Specifies the y-coordinate of the upper-left corner of the region in logical units. + /// Specifies the x-coordinate of the lower-right corner of the region in logical units. + /// Specifies the y-coordinate of the lower-right corner of the region in logical units. + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// Region coordinates are represented as 27-bit signed integers. + /// + /// Regions created by the Create<shape>Rgn methods (such as CreateRectRgn and CreatePolygonRgn) only include the + /// interior of the shape; the shape's outline is excluded from the region. This means that any point on a line between two + /// sequential vertices is not included in the region. If you were to call PtInRegion for such a point, it would return zero as the result. + /// + /// Examples + /// For an example, see Drawing Markers. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createrectrgn HRGN CreateRectRgn( int x1, int y1, int x2, + // int y2 ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "17456440-c655-48ab-8d1e-ee770330f164")] + public static extern SafeHRGN CreateRectRgn(int x1, int y1, int x2, int y2); + + /// The CreateRectRgnIndirect function creates a rectangular region. + /// + /// Pointer to a RECT structure that contains the coordinates of the upper-left and lower-right corners of the rectangle that defines + /// the region in logical units. + /// + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object, call the DeleteObject function to delete it. + /// Region coordinates are represented as 27-bit signed integers. + /// The region will be exclusive of the bottom and right edges. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createrectrgnindirect HRGN CreateRectRgnIndirect( const RECT + // *lprect ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "f32e0b94-ce9c-4098-81fe-b239a9544621")] + public static extern SafeHRGN CreateRectRgnIndirect(in RECT lprect); + + /// The CreateRoundRectRgn function creates a rectangular region with rounded corners. + /// Specifies the x-coordinate of the upper-left corner of the region in device units. + /// Specifies the y-coordinate of the upper-left corner of the region in device units. + /// Specifies the x-coordinate of the lower-right corner of the region in device units. + /// Specifies the y-coordinate of the lower-right corner of the region in device units. + /// Specifies the width of the ellipse used to create the rounded corners in device units. + /// Specifies the height of the ellipse used to create the rounded corners in device units. + /// + /// If the function succeeds, the return value is the handle to the region. + /// If the function fails, the return value is NULL. + /// + /// + /// When you no longer need the HRGN object call the DeleteObject function to delete it. + /// Region coordinates are represented as 27-bit signed integers. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createroundrectrgn HRGN CreateRoundRectRgn( int x1, int y1, + // int x2, int y2, int w, int h ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "16f387e1-b00c-4755-8b21-1ee0f25bc46b")] + public static extern SafeHRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int w, int h); + + /// + /// The EqualRgn function checks the two specified regions to determine whether they are identical. The function considers two + /// regions identical if they are equal in size and shape. + /// + /// Handle to a region. + /// Handle to a region. + /// + /// If the two regions are equal, the return value is nonzero. + /// + /// If the two regions are not equal, the return value is zero. A return value of ERROR means at least one of the region handles is invalid. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-equalrgn BOOL EqualRgn( HRGN hrgn1, HRGN hrgn2 ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "c7829998-78f4-4334-bf34-92aad12555f5")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool EqualRgn(HRGN hrgn1, HRGN hrgn2); + + /// The ExtCreateRegion function creates a region from the specified region and transformation data. + /// + /// A pointer to an XFORM structure that defines the transformation to be performed on the region. If this pointer is NULL, + /// the identity transformation is used. + /// + /// The number of bytes pointed to by lpRgnData. + /// A pointer to a RGNDATA structure that contains the region data in logical units. + /// + /// If the function succeeds, the return value is the value of the region. + /// If the function fails, the return value is NULL. + /// + /// + /// Region coordinates are represented as 27-bit signed integers. + /// An application can retrieve data for a region by calling the GetRegionData function. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-extcreateregion HRGN ExtCreateRegion( const XFORM *lpx, + // DWORD nCount, const RGNDATA *lpData ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "4dcff824-eb1d-425c-b246-db4ace2c6518")] + public static extern SafeHRGN ExtCreateRegion(in XFORM lpx, uint nCount, [In] RGNDATA lpData); + + /// The FillRgn function fills a region by using the specified brush. + /// Handle to the device context. + /// Handle to the region to be filled. The region's coordinates are presumed to be in logical units. + /// Handle to the brush to be used to fill the region. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-fillrgn BOOL FillRgn( HDC hdc, HRGN hrgn, HBRUSH hbr ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "c4e0eca5-442b-462b-a4f2-0c628b6d3d38")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool FillRgn(HDC hdc, HRGN hrgn, HBRUSH hbr); + + /// The FrameRgn function draws a border around the specified region by using the specified brush. + /// Handle to the device context. + /// + /// Handle to the region to be enclosed in a border. The region's coordinates are presumed to be in logical units. + /// + /// Handle to the brush to be used to draw the border. + /// Specifies the width, in logical units, of vertical brush strokes. + /// Specifies the height, in logical units, of horizontal brush strokes. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-framergn BOOL FrameRgn( HDC hdc, HRGN hrgn, HBRUSH hbr, int + // w, int h ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "d2c95392-7950-4963-8f10-2387daf23e93")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool FrameRgn(HDC hdc, HRGN hrgn, HBRUSH hbr, int w, int h); + + /// The GetPolyFillMode function retrieves the current polygon fill mode. + /// Handle to the device context. + /// + /// If the function succeeds, the return value specifies the polygon fill mode, which can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// ALTERNATE + /// Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line). + /// + /// + /// WINDING + /// Selects winding mode (fills any region with a nonzero winding value). + /// + /// + /// If an error occurs, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getpolyfillmode int GetPolyFillMode( HDC hdc ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "febf96fb-bf2e-4eb2-ab5f-89741a1decad")] + public static extern System.Drawing.Drawing2D.FillMode GetPolyFillMode(HDC hdc); + + /// + /// The GetRegionData function fills the specified buffer with data describing a region. This data includes the dimensions of + /// the rectangles that make up the region. + /// + /// A handle to the region. + /// The size, in bytes, of the lpRgnData buffer. + /// + /// A pointer to a RGNDATA structure that receives the information. The dimensions of the region are in logical units. If this + /// parameter is NULL, the return value contains the number of bytes needed for the region data. + /// + /// + /// + /// If the function succeeds and dwCount specifies an adequate number of bytes, the return value is always dwCount. If dwCount is too + /// small or the function fails, the return value is 0. If lpRgnData is NULL, the return value is the required number of bytes. + /// + /// If the function fails, the return value is zero. + /// + /// The GetRegionData function is used in conjunction with the ExtCreateRegion function. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getregiondata DWORD GetRegionData( HRGN hrgn, DWORD nCount, + // LPRGNDATA lpRgnData ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "e0d4862d-a405-4c00-b7b0-af4dd60407c0")] + public static extern uint GetRegionData(HRGN hrgn, uint nCount, [In, Out] RGNDATA lpRgnData); + + /// The GetRgnBox function retrieves the bounding rectangle of the specified region. + /// A handle to the region. + /// A pointer to a RECT structure that receives the bounding rectangle in logical units. + /// + /// The return value specifies the region's complexity. It can be one of the following values: + /// + /// + /// Value + /// Meaning + /// + /// + /// NULLREGION + /// Region is empty. + /// + /// + /// SIMPLEREGION + /// Region is a single rectangle. + /// + /// + /// COMPLEXREGION + /// Region is more than a single rectangle. + /// + /// + /// If the hrgn parameter does not identify a valid region, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-getrgnbox int GetRgnBox( HRGN hrgn, LPRECT lprc ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "42d06f7f-1bf3-418f-a3b9-c009cf2de10b")] + public static extern RGN_TYPE GetRgnBox(HRGN hrgn, out RECT lprc); + + /// The InvertRgn function inverts the colors in the specified region. + /// Handle to the device context. + /// + /// Handle to the region for which colors are inverted. The region's coordinates are presumed to be logical coordinates. + /// + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + /// + /// + /// On monochrome screens, the InvertRgn function makes white pixels black and black pixels white. On color screens, this + /// inversion is dependent on the type of technology used to generate the colors for the screen. + /// + /// Examples + /// For an example, see Using Brushes. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-invertrgn BOOL InvertRgn( HDC hdc, HRGN hrgn ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "94704c44-796a-4ca7-97f3-6676d7f94078")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool InvertRgn(HDC hdc, HRGN hrgn); + + /// The OffsetRgn function moves a region by the specified offsets. + /// Handle to the region to be moved. + /// Specifies the number of logical units to move left or right. + /// Specifies the number of logical units to move up or down. + /// + /// The return value specifies the new region's complexity. It can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// NULLREGION + /// Region is empty. + /// + /// + /// SIMPLEREGION + /// Region is a single rectangle. + /// + /// + /// COMPLEXREGION + /// Region is more than one rectangle. + /// + /// + /// ERROR + /// An error occurred; region is unaffected. + /// + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-offsetrgn int OffsetRgn( HRGN hrgn, int x, int y ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "5228c614-3278-4852-a867-7eed57359aef")] + public static extern RGN_TYPE OffsetRgn(HRGN hrgn, int x, int y); + + /// The PaintRgn function paints the specified region by using the brush currently selected into the device context. + /// Handle to the device context. + /// Handle to the region to be filled. The region's coordinates are presumed to be logical coordinates. + /// + /// If the function succeeds, the return value is nonzero. + /// If the function fails, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-paintrgn BOOL PaintRgn( HDC hdc, HRGN hrgn ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "7656fb67-d865-459e-b379-4f2e44c76fd0")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PaintRgn(HDC hdc, HRGN hrgn); + + /// The PtInRegion function determines whether the specified point is inside the specified region. + /// Handle to the region to be examined. + /// Specifies the x-coordinate of the point in logical units. + /// Specifies the y-coordinate of the point in logical units. + /// + /// If the specified point is in the region, the return value is nonzero. + /// If the specified point is not in the region, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-ptinregion BOOL PtInRegion( HRGN hrgn, int x, int y ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "6fab6126-4672-49d6-825b-66a7927a7e99")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool PtInRegion(HRGN hrgn, int x, int y); + + /// + /// The RectInRegion function determines whether any part of the specified rectangle is within the boundaries of a region. + /// + /// Handle to the region. + /// + /// Pointer to a RECT structure containing the coordinates of the rectangle in logical units. The lower and right edges of the + /// rectangle are not included. + /// + /// + /// If any part of the specified rectangle lies within the boundaries of the region, the return value is nonzero. + /// If no part of the specified rectangle lies within the boundaries of the region, the return value is zero. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-rectinregion BOOL RectInRegion( HRGN hrgn, const RECT + // *lprect ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "198a02f1-120c-4f65-aa7c-a41f2e5e81a9")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool RectInRegion(HRGN hrgn, in RECT lprect); + + /// The SetPolyFillMode function sets the polygon fill mode for functions that fill polygons. + /// A handle to the device context. + /// + /// The new fill mode. This parameter can be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// ALTERNATE + /// Selects alternate mode (fills the area between odd-numbered and even-numbered polygon sides on each scan line). + /// + /// + /// WINDING + /// Selects winding mode (fills any region with a nonzero winding value). + /// + /// + /// + /// The return value specifies the previous filling mode. If an error occurs, the return value is zero. + /// + /// + /// In general, the modes differ only in cases where a complex, overlapping polygon must be filled (for example, a five-sided polygon + /// that forms a five-pointed star with a pentagon in the center). In such cases, ALTERNATE mode fills every other enclosed region + /// within the polygon (that is, the points of the star), but WINDING mode fills all regions (that is, the points and the pentagon). + /// + /// + /// When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and even-numbered polygon sides on each scan line. That + /// is, GDI fills the area between the first and second side, between the third and fourth side, and so on. + /// + /// + /// When the fill mode is WINDING, GDI fills any region that has a nonzero winding value. This value is defined as the number of + /// times a pen used to draw the polygon would go around the region. The direction of each edge of the polygon is important. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpolyfillmode int SetPolyFillMode( HDC hdc, int mode ); + [DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)] + [PInvokeData("wingdi.h", MSDNShortId = "233926c4-2658-405d-89b6-05ece844623d")] + public static extern System.Drawing.Drawing2D.FillMode SetPolyFillMode(HDC hdc, System.Drawing.Drawing2D.FillMode mode); + + /// The RGNDATAHEADER structure describes the data returned by the GetRegionData function. + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_rgndataheader typedef struct _RGNDATAHEADER { DWORD dwSize; + // DWORD iType; DWORD nCount; DWORD nRgnSize; RECT rcBound; } RGNDATAHEADER, *PRGNDATAHEADER; + [PInvokeData("wingdi.h", MSDNShortId = "15990903-8a48-4c47-b527-269d775255a5")] + [StructLayout(LayoutKind.Sequential)] + public struct RGNDATAHEADER + { + /// The size, in bytes, of the header. + public uint dwSize; + + /// The type of region. This value must be RDH_RECTANGLES. + public RDH iType; + + /// The number of rectangles that make up the region. + public uint nCount; + + /// + /// The size of the RGNDATA buffer required to receive the RECT structures that make up the region. If the size is not known, + /// this member can be zero. + /// + public int nRgnSize; + + /// A bounding rectangle for the region in logical units. + public RECT rcBound; + } + + /// The XFORM structure specifies a world-space to page-space transformation. + /// + /// The following list describes how the members are used for each operation. + /// + /// + /// Operation + /// eM11 + /// eM12 + /// eM21 + /// eM22 + /// + /// + /// Rotation + /// Cosine + /// Sine + /// Negative sine + /// Cosine + /// + /// + /// Scaling + /// Horizontal scaling component + /// Not used + /// Not used + /// Vertical Scaling Component + /// + /// + /// Shear + /// Not used + /// Horizontal Proportionality Constant + /// Vertical Proportionality Constant + /// Not used + /// + /// + /// Reflection + /// Horizontal Reflection Component + /// Not used + /// Not used + /// Vertical Reflection Component + /// + /// + /// + // 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 + { + /// + /// The following. + /// + /// + /// Operation + /// Meaning + /// + /// + /// Scaling + /// Horizontal scaling component + /// + /// + /// Rotation + /// Cosine of rotation angle + /// + /// + /// Reflection + /// Horizontal component + /// + /// + /// + public float eM11; + + /// + /// The following. + /// + /// + /// Operation + /// Meaning + /// + /// + /// Shear + /// Horizontal proportionality constant + /// + /// + /// Rotation + /// Sine of the rotation angle + /// + /// + /// + public float eM12; + + /// + /// The following. + /// + /// + /// Operation + /// Meaning + /// + /// + /// Shear + /// Vertical proportionality constant + /// + /// + /// Rotation + /// Negative sine of the rotation angle + /// + /// + /// + public float eM21; + + /// + /// The following. + /// + /// + /// Operation + /// Meaning + /// + /// + /// Scaling + /// Vertical scaling component + /// + /// + /// Rotation + /// Cosine of rotation angle + /// + /// + /// Reflection + /// Vertical reflection component + /// + /// + /// + public float eM22; + + /// The horizontal translation component, in logical units. + public float eDx; + + /// The vertical translation component, in logical units. + public float eDy; + } + + /// + /// The RGNDATA structure contains a header and an array of rectangles that compose a region. The rectangles are sorted top to + /// bottom, left to right. They do not overlap. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_rgndata typedef struct _RGNDATA { RGNDATAHEADER rdh; char + // Buffer[1]; } RGNDATA, *PRGNDATA, *NPRGNDATA, *LPRGNDATA; + [PInvokeData("wingdi.h", MSDNShortId = "3eac0b23-3138-4b34-9c16-6cc185e4de22")] + [StructLayout(LayoutKind.Sequential)] + public class RGNDATA : IDisposable + { + /// + /// A RGNDATAHEADER structure. The members of this structure specify the type of region (whether it is rectangular or + /// trapezoidal), the number of rectangles that make up the region, the size of the buffer that contains the rectangle + /// structures, and so on. + /// + public RGNDATAHEADER rdh; + + private IntPtr _Buffer; + + /// Specifies an arbitrary-size buffer that contains the RECT structures that make up the region. + public RECT[] Buffer + { + get => _Buffer.ToArray((int)rdh.nCount); + set + { + ((IDisposable)this).Dispose(); + value = value ?? new RECT[0]; + _Buffer = value.MarshalToPtr(Marshal.AllocHGlobal, out rdh.nRgnSize); + rdh.nCount = (uint)value.Length; + } + } + + /// Gets the size, in bytes, of the structure with allocated memory for . + public uint Size => rdh.dwSize + (uint)rdh.nRgnSize; + + /// Initializes a new instance of the class. + /// A bounding rectangle for the region in logical units. + /// The number of rectangles that make up the region. + public RGNDATA(in RECT bounds, int count) + { + rdh.dwSize = (uint)Marshal.SizeOf(typeof(RGNDATAHEADER)); + rdh.iType = RDH.RDH_RECTANGLES; + Buffer = new RECT[count]; + rdh.rcBound = bounds; + } + + /// Initializes a new instance of the class. + /// A bounding rectangle for the region in logical units. + /// The RECT structures that make up the region. + public RGNDATA(in RECT bounds, RECT[] rects) + { + rdh.dwSize = (uint)Marshal.SizeOf(typeof(RGNDATAHEADER)); + rdh.iType = RDH.RDH_RECTANGLES; + Buffer = rects; + rdh.rcBound = bounds; + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + void IDisposable.Dispose() { Marshal.FreeHGlobal(_Buffer); _Buffer = IntPtr.Zero; } + } + } +} \ No newline at end of file