How to Reference Colors in a DIB Section by IndexID: Q138256
|
When using the GDI with DIB sections (HBITMAPs returned by a call to CreateDIBSection()), you may need a way to reference the colors in the color table of the DIB section by index rather than by RGB value. This article shows you how.
To reference a color table value by index, use the DIBINDEX macro defined
in Mmsystem.h. It allows you to index the colors in the color table of a
DIB section in a manner similar to the way PALETTEINDEX indexes a color in
a logical palette. In other words, you can create COLORREFs that reference
a DIB section's color table rather than the logical palette in the DC that
the DIB section is selected into. Because DIBINDEX references values in a
color table, it only works on DCs where you have a DIB section selected.
The DIBINDEX macro accepts an index to a color table entry and returns a
color table specifier consisting of a 32-bit COLORREF value that specifies
the color associated with the given index. An application using a display
context with a DIB section selected into it can pass this specifier,
instead of an explicit red, green, blue (RGB) value, to GDI functions that
expect a color. This allows the function to use the color at the specified
color table index.
LONG DIBINDEX(
WORD wColorTableIndex // index to color table entry
);
Parameters
wColorTableIndex - Specifies an index to the palette entry containing
the color to be used for a graphics operation.
Return Value
The return value is a color table index specifier.
Remarks
DIBINDEX is defined as:
#define DIBINDEX(n) MAKELONG((n),0x10FF)
Additional query words: 3.10 3.50 4.00 Windows 95 COLORTABLE HBITMAP BRUSH COLORREF PEN DIBSECTION
Keywords : kbcode
Version : 4.00 | 3.10 3.50 3.51
Platform : NT WINDOWS
Issue type :
Last Reviewed: March 5, 1999