Microsoft KB Archive/138256

{|
 * width="100%"|

HOWTO: Reference Colors in a DIB Section by Index

 * }

Q138256

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5, 3.51, 4.0
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

-

SUMMARY
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.

MORE INFORMATION
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)

NOTE: DIBINDEX also works with 16-bit WinGBitmaps and WinGDCs.

Additional query words: 3.10 3.50 4.00 Windows 95 COLORTABLE HBITMAP BRUSH COLORREF PEN DIBSECTION

Keywords : _IK kbOSWin2000

Issue type : kbhowto

Technology : kbwin2000AdvServ kbwin2000AdvServSearch kbwin2000Serv kbwin2000ServSearch kbwin2000Search kbwin2000ProSearch kbwin2000Pro kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWinAdvServSearch kbWin32sSearch kbWin32SDK400 kbWin32SDK310 kbWin32SDK350 kbWin32SDK351