mirror of https://github.com/dahall/Vanara.git
Fixed LOGPALETTE structure and related functions
parent
54b1923a26
commit
f7168cf0e1
File diff suppressed because it is too large
Load Diff
|
@ -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.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,97 +1,91 @@
|
|||
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.
|
||||
/// </summary>
|
||||
PC_EXPLICIT = 0x2,
|
||||
/// <summary>
|
||||
/// Specifies that the low-order word of the logical palette entry designates a hardware palette index. This flag allows the
|
||||
/// application to show the contents of the display device palette.
|
||||
/// </summary>
|
||||
PC_EXPLICIT = 0x2,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that the color be placed in an unused entry in the system palette instead of being matched to an existing color in
|
||||
/// the system palette. If there are no unused entries in the system palette, the color is matched normally. Once this color is
|
||||
/// in the system palette, colors in other logical palettes can be matched to this color.
|
||||
/// </summary>
|
||||
PC_NOCOLLAPSE = 0x4,
|
||||
/// <summary>
|
||||
/// Specifies that the color be placed in an unused entry in the system palette instead of being matched to an existing color in
|
||||
/// the system palette. If there are no unused entries in the system palette, the color is matched normally. Once this color is
|
||||
/// in the system palette, colors in other logical palettes can be matched to this color.
|
||||
/// </summary>
|
||||
PC_NOCOLLAPSE = 0x4,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies that the logical palette entry be used for palette animation. This flag prevents other windows from matching colors
|
||||
/// to the palette entry since the color frequently changes. If an unused system-palette entry is available, the color is placed
|
||||
/// in that entry. Otherwise, the color is not available for animation.
|
||||
/// </summary>
|
||||
PC_RESERVED = 0x1,
|
||||
}
|
||||
/// <summary>
|
||||
/// Specifies that the logical palette entry be used for palette animation. This flag prevents other windows from matching colors
|
||||
/// to the palette entry since the color frequently changes. If an unused system-palette entry is available, the color is placed
|
||||
/// in that entry. Otherwise, the color is not available for animation.
|
||||
/// </summary>
|
||||
PC_RESERVED = 0x1,
|
||||
}
|
||||
|
||||
/// <summary>The <c>LOGPALETTE</c> structure defines a logical palette.</summary>
|
||||
/// <remarks>
|
||||
/// The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are
|
||||
/// most likely to be placed in the system palette.
|
||||
/// </remarks>
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
|
||||
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
|
||||
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class LOGPALETTE : IDisposable
|
||||
{
|
||||
/// <summary>The version number of the system.</summary>
|
||||
public ushort palVersion;
|
||||
/// <summary>The <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;
|
||||
/// <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>
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
|
||||
public PALETTEENTRY[]? 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 _); }
|
||||
}
|
||||
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
|
||||
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
|
||||
[PInvokeData("wingdi.h")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PALETTEENTRY
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The red intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peRed;
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry);
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The green intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peGreen;
|
||||
|
||||
/// <summary>Specifies the color and usage of an entry in a logical palette.</summary>
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
|
||||
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
|
||||
[PInvokeData("wingdi.h")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PALETTEENTRY
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The red intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peRed;
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The blue intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peBlue;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The green intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peGreen;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>The blue intensity value for the palette entry.</para>
|
||||
/// </summary>
|
||||
public byte peBlue;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>
|
||||
/// The alpha intensity value for the palette entry. Note that as of DirectX 8, this member is treated differently than
|
||||
/// documented for Windows.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public PC peFlags;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>Type: <c>BYTE</c></para>
|
||||
/// <para>
|
||||
/// The alpha intensity value for the palette entry. Note that as of DirectX 8, this member is treated differently than
|
||||
/// documented for Windows.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public PC peFlags;
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue