How To Distinguish Between DIB Sections And Device Dependent Bit (187539)



The information in this article applies to:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional
  • Microsoft Platform Software Development Kit (SDK) 1.0

This article was previously published under Q187539

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: <WWLINK TYPE="ARTICLE" VALUE="Q186221">Q186221</WWLINK>
				
   TITLE     : SAMPLE: DibSectn.exe Uses DIBSections in Win32
				

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbhowto KB187539