How to Reference Colors in a DIB Section by Index

Last reviewed: March 8, 1996
Article ID: Q138256
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) versions 3.1, 3.5, 3.51, 4.0

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 reference words: 3.10 3.50 4.00 Windows 95 COLORTABLE HBITMAP
BRUSH COLORREF PEN DIBSECTION
KBCategory: kbprg kbhowto kbcode
KBSubcategory: W32


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 8, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.