HOWTO: Distinguish Between DIB Sections & Device-Dependent Bit

ID: Q187539

The information in this article applies to:

SUMMARY

In some cases, you might need to know whether a particular bitmap handle references a DIB section or a device-dependent bitmap. To discern between the two bitmap types, call GetObject() on the handle and get it to fill out a BITMAP structure. After the call to GetObject(), the bmBits field of the BITMAP structure will contain a pointer to the surface of the DIB section if the handle references a DIB section and NULL if the handle references a device-dependent bitmap (DDB).

MORE INFORMATION

Sample Code

   // IsDIBSection()
   //
   // When passed the handle to a bitmap, IsDIBSection()
   // will return TRUE if the bitmap referenced by the handle
   // is a DIB section and FALSE if the handle references a
   // device-dependent bitmap or is not a handle to a bitmap.
   BOOL IsDIBSection(HANDLE hBitmap)
   {
       BITMAP bm;

       if (!GetObject(hBitmap, sizeof(bm), &bm))
          return FALSE;  // It's not even a handle to a bitmap!

       // If there is a pointer to the surface in the bmBits, this
       // indicates that the handle is a handle to a DIB section.
       return (BOOL)bm.bmBits;
   }

REFERENCES

For additional information on DIB sections, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q186221
   TITLE     : SAMPLE: DibSectn.exe Uses DIBSections in Win32

Additional query words: kbDSupport kbGDI kbBitmap
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: June 10, 1998