Fixed LOGPALETTE structure and related functions

nullableenabled
David Hall 2023-02-20 07:58:13 -07:00
parent 54b1923a26
commit f7168cf0e1
5 changed files with 8378 additions and 8377 deletions

View File

@ -1,12 +1,12 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
namespace Vanara.PInvoke;
public static partial class Gdi32
{
public static partial class Gdi32
{
/// <summary>
/// The <c>EnumICMProfilesProcCallback</c> callback is an application-defined callback function that processes color profile data
/// from <c>EnumICMProfiles</c> .
@ -373,9 +373,9 @@ namespace Vanara.PInvoke
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-createpalette HPALETTE CreatePalette( const LOGPALETTE
// *plpal );
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("wingdi.h", MSDNShortId = "f3462198-9360-4b77-ac62-9fe21ec666be")]
public static extern SafeHPALETTE CreatePalette([In] LOGPALETTE plpal);
[DllImport(Lib.Gdi32, SetLastError = false, ExactSpelling = true)]
public static extern SafeHPALETTE CreatePalette([In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] LOGPALETTE plpal);
/// <summary>The <c>DeleteColorSpace</c> function removes and destroys a specified color space.</summary>
/// <param name="hcs">Specifies the handle to a color space to delete.</param>
@ -1491,5 +1491,4 @@ namespace Vanara.PInvoke
/// <inheritdoc/>
protected override bool InternalReleaseHandle() => DeleteColorSpace(handle);
}
}
}

View File

@ -8289,7 +8289,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
new unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.

View File

@ -2,11 +2,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Vanara.InteropServices;
namespace Vanara.PInvoke
namespace Vanara.PInvoke;
public static partial class Ole32
{
public static partial class Ole32
{
/// <summary>Specifies what to do with caches that are to be discarded from memory if their dirty bit has been set.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/ne-oleidl-discardcache typedef enum tagDISCARDCACHE {
// DISCARDCACHE_SAVEIFDIRTY, DISCARDCACHE_NOSAVE } DISCARDCACHE;
@ -5685,7 +5686,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-ioleobject-setcolorscheme HRESULT SetColorScheme(
// LOGPALETTE *pLogpal );
[PreserveSig]
HRESULT SetColorScheme(IntPtr pLogpal);
HRESULT SetColorScheme([In, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] LOGPALETTE pLogpal);
}
/// <summary>
@ -6208,7 +6209,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.
@ -6658,7 +6659,7 @@ namespace Vanara.PInvoke
// https://docs.microsoft.com/en-us/windows/win32/api/oleidl/nf-oleidl-iviewobject-getcolorset HRESULT GetColorSet( DWORD
// dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet );
new unsafe HRESULT GetColorSet(DVASPECT dwDrawAspect, int lindex, [In, Optional] DVASPECTINFO* pvAspect, [In, Optional] DVTARGETDEVICE* ptd,
[In, Optional] HDC hicTargetDev, out LOGPALETTE ppColorSet);
[In, Optional] HDC hicTargetDev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(VanaraCustomMarshaler<LOGPALETTE>))] out LOGPALETTE ppColorSet);
/// <summary>
/// Freezes the drawn representation of an object so that it will not change until the IViewObject::Unfreeze method is called.
@ -6969,5 +6970,4 @@ namespace Vanara.PInvoke
/// <summary>Combination of the verb attributes in the OLEVERBATTRIB enumeration.</summary>
public OLEVERBATTRIB grfAttribs;
}
}
}

View File

@ -1,14 +1,16 @@
using System;
#nullable enable
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
namespace Vanara.PInvoke;
/// <summary>The alpha intensity value for the palette entry.</summary>
[PInvokeData("wingdi.h")]
[Flags]
public enum PC : byte
{
/// <summary>The alpha intensity value for the palette entry.</summary>
[PInvokeData("wingdi.h")]
[Flags]
public enum PC : byte
{
/// <summary>
/// Specifies that the low-order word of the logical palette entry designates a hardware palette index. This flag allows the
/// application to show the contents of the display device palette.
@ -28,45 +30,38 @@ namespace Vanara.PInvoke
/// in that entry. Otherwise, the color is not available for animation.
/// </summary>
PC_RESERVED = 0x1,
}
}
/// <summary>The <c>LOGPALETTE</c> structure defines a logical palette.</summary>
/// <remarks>
/// The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are
/// most likely to be placed in the system palette.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
[StructLayout(LayoutKind.Sequential)]
public class LOGPALETTE : IDisposable
{
/// <summary>The <c>LOGPALETTE</c> structure defines a logical palette.</summary>
/// <remarks>
/// The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are
/// most likely to be placed in the system palette.
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
[VanaraMarshaler(typeof(SafeAnysizeStructMarshaler<LOGPALETTE>), nameof(palNumEntries))]
[StructLayout(LayoutKind.Sequential)]
public class LOGPALETTE
{
/// <summary>The version number of the system.</summary>
public ushort palVersion;
/// <summary>The number of entries in the logical palette.</summary>
public ushort palNumEntries;
private IntPtr _palPalEntry;
/// <summary>Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.</summary>
public PALETTEENTRY[] palPalEntry
{
get => _palPalEntry.ToArray<PALETTEENTRY>(palNumEntries);
set { Marshal.FreeHGlobal(_palPalEntry); value.MarshalToPtr<PALETTEENTRY>(Marshal.AllocHGlobal, out _); }
}
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public PALETTEENTRY[]? palPalEntry;
}
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry);
}
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
[PInvokeData("wingdi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct PALETTEENTRY
{
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
[PInvokeData("wingdi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct PALETTEENTRY
{
/// <summary>
/// <para>Type: <c>BYTE</c></para>
/// <para>The red intensity value for the palette entry.</para>
@ -93,5 +88,4 @@ namespace Vanara.PInvoke
/// </para>
/// </summary>
public PC peFlags;
}
}

View File

@ -34,6 +34,14 @@ namespace Vanara.PInvoke.Tests
Assert.That(CreateFont(), ResultIs.ValidHandle);
}
[Test]
public void CreatePaletteTest()
{
LOGPALETTE lp = new() { palVersion = 0x300, palNumEntries = 32, palPalEntry = new PALETTEENTRY[32] };
for (int i = 0;i < 32; i++) { lp.palPalEntry[i] = new() { peFlags = PC.PC_NOCOLLAPSE }; }
Assert.That(CreatePalette(lp), ResultIs.ValidHandle);
}
// TODO: [Test]
public void DeleteDCTest()
{