Microsoft KB Archive/187539

{|
 * width="100%"|

HOWTO: Distinguish Between DIB Sections And Device Dependent Bit

 * }

Q187539

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

-

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

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; }