Microsoft Windows CE 3.0  

Device-Independent Bitmaps

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Windows CE and DirectX uses the device-independent bitmap (DIB) as its native graphics file format. Essentially, a DIB is a file that contains information describing an image's dimensions, the number of colors it uses, values describing those colors, and data that describes each pixel. Additionally, a DIB contains some lesser-used parameters, like information about file compression, significant colors (if all are not used), and physical dimensions of the image (in case it will end up in print). DIB files usually have the .bmp file extension, although they might occasionally have a .dib extension.

Because the DIB is so pervasive in Windows programming, Windows CE already contains many functions that you can use with DirectX. For example, the following application-defined function combines Windows CE and DirectX functions to load a DIB onto a DirectX surface.

extern "C" IDirectDrawSurface *
DDLoadBitmap(IDirectDraw *pdd, LPCSTR szBitmap, int dx, int dy) {
HBITMAP hbm; BITMAP bm; DDSURFACEDESC ddsd; IDirectDrawSurface
*pdds; // // This is the Windows CE part. // Try to load the bitmap
as a resource. // If that fails, try it as a file. // hbm =
(HBITMAP)LoadImage( GetModuleHandle(NULL), szBitmap, IMAGE_BITMAP,
dx, dy, LR_CREATEDIBSECTION); if (hbm == NULL) hbm =
(HBITMAP)LoadImage( NULL, szBitmap, IMAGE_BITMAP, dx, dy,
LR_LOADFROMFILE|LR_CREATEDIBSECTION); if (hbm == NULL) return NULL;
// // Get the size of the bitmap. // if (0 == GetObject(hbm,
sizeof(bm), &bm)) { DeleteObject(hbm); return NULL; } // //
Now, return to DirectX function calls. // Create a
DirectDrawSurface for this bitmap. // memset(&ddsd, 0,
sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS
| DDSD_HEIGHT |DDSD_WIDTH; ddsd.ddsCaps.dwCaps =
DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = bm.bmWidth; ddsd.dwHeight =
bm.bmHeight; if (pdd->CreateSurface(&ddsd, &pdds, NULL)
!= DD_OK) return NULL; DDCopyBitmap(pdds, hbm, 0, 0, 0, 0);
DeleteObject(hbm); return pdds; }

For more detailed information about DIB files, see Using Bitmaps.



 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.