HOWTO: Distinguish Between DIB Sections And Device Dependent Bit

ID: Q187539


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows 2000


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: <LINK TYPE="ARTICLE" VALUE="Q186221">Q186221</LINK> 

   TITLE     : SAMPLE: DibSectn.exe Uses DIBSections in Win32 

Additional query words: kbDSupport kbGDI kbBitmap

Keywords : kbWinOS2000
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: December 20, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.