Article ID: 186586
Article Last Modified on 2/22/2007
// Code to create a DIB section that will be used as
// a test case.
HBITMAP CreateADIBSection(int iWidth, int iHeight)
{
BITMAPINFO bmi;
BYTE *pBits;
HDC hdc = GetDC(NULL);
HBITMAP hbm;
// Initialize the header.
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = iWidth;
bmi.bmiHeader.biHeight = iHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
// Create the surface.
hbm = CreateDIBSection(hdc, // Handle to device context.
&bmi, // Pointer to creation parameters
DIB_RGB_COLORS, // Unused.
&pBits, // Address of pointer to surface.
NULL, // No file mapping object.
0); // No offset.
// Clean up.
ReleaseDC(NULL, hdc);
return(hbm);
}
// Create a DIB section with a negative height, and then
// display its height as returned from GetObject().
{
char szMessage[128];
int nHeight = -100;
HBITMAP hbm = CreateADIBSection(10, nHeight); // Create a test
// case.
DIBSECTION ds;
// Fill out a DIBSECTION for the test case.
GetObject(hbm, sizeof(ds), &ds);
wsprintf(szMessage, "Created with height: %li\n" "Height reported by GetObject(): %li", nHeight, ds.dsBmih.biHeight);
MessageBox(NULL, szMessage, "Status...", MB_ICONINFORMATION);
}
Additional query words: kbdsd kbGDI kbBitmap kbDSupport
Keywords: kbcode kbfaq kbprb KB186586