TPalette encapsulates a number of standard API calls for manipulating palettes:
- You can match a color with an entry in a palette using the
- TPalette::GetNearestPaletteIndex function. This function takes a single parameter (a Tcolor object) and returns the index number of the closest match in the palette's color table.
- TPalette::GetNumEntries takes no parameters and returns the number of entries in the palette's color table.
- You can get the values for a range of entries in the palette's color table using the TPalette::GetPaletteEntries function. TPalette::GetPaletteEntries functions just like the Windows API call GetPaletteEntries, except that TPalette::GetPaletteEntries omits the HPALETTE parameter.
- You can set the values for a range of entries in the palette's color table using the TPalette::SetPaletteEntries function. TPalette::SetPaletteEntries functions just like the Windows API call SetPaletteEntries, except that TPalette::SetPaletteEntries omits the HPALETTE parameter.
- The TPalette::GetPaletteEntry and TPalette::SetPaletteEntry functions work much like GetPaletteEntries and SetPaletteEntries, except that they work on a single palette entry at a time. Both functions take two parameters, the index number of a palette entry and a reference to a PALETTEENTRY object. GetPaletteEntry places the color value of the desired palette entry into the PALETTEENTRY object. SetPaletteEntry sets the palette entry indicated by the index to the value of the PALETTEENTRY object.
- You can use the TPalette::ResizePalette function to resize a palette. ResizePalette takes a uint parameter, which specifies the number of entries in the resized palette. ResizePalette functions exactly like the Windows API ResizePalette call.
- The TPalette::AnimatePalette function lets you replace entries in the palette's color table. AnimatePalette takes three parameters, two uints and a pointer to an array of PALETTEENTRY objects. The first uint specifies the first entry in the palette to be replaced. The second uint specifies the number of entries to be replaced. The entries indicated by these two uints are replaced by the values contained in the array of PALETTEENTRYs.
- You can also use the TPalette::UnrealizeObject function for your palette objects. UnrealizeObject matches the palette to the current system palette. UnrealizeObject takes no parameters and functions just like the Windows API call.
- You can move a palette to the Clipboard using the TPalette::ToClipboard function. ToClipboard takes a reference to a TClipboard object as a parameter. Because the ToClipboard function actually removes the object from your application, you should usually use a TPalette constructor to create a temporary object as follows:
See Also