// Retrieve the bitmap color format, width, and height.
//根据位图句柄获取位图信息
if (!GetObject(hbmScreen, sizeof(BITMAP), (LPSTR)&bmp))
{
AfxMessageBox("GetObject");
return;
}
// Convert the color format to a count of bits.
BitsPerPixel = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
if (BitsPerPixel == 1)
BitsPerPixel = 1;
else if (BitsPerPixel <= 4)
BitsPerPixel = 4;
else if (BitsPerPixel <= 8)
BitsPerPixel = 8;
else if (BitsPerPixel <= 16)
BitsPerPixel = 16;
else if (BitsPerPixel <= 24)
BitsPerPixel = 24;
else BitsPerPixel = 32;
// Allocate memory for the BITMAPINFO structure. (This structure
// contains a BITMAPINFOHEADER structure and an array of RGBQUAD
// data structures.)
// If the bitmap is not compressed, set the BI_RGB flag.
pbmi->bmiHeader.biCompression = BI_RGB;
// Compute the number of bytes in the array of color
// indices and store the result in biSizeImage.
// For Windows NT, the width must be DWORD aligned unless
// the bitmap is RLE compressed. This example shows this.
// For Windows 95/98/Me, the width must be WORD aligned unless the
// bitmap is RLE compressed.
pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * BitsPerPixel +31) & ~31) /8
* pbmi->bmiHeader.biHeight;
// Set biClrImportant to 0, indicating that all of the
// device colors are important.
pbmi->bmiHeader.biClrImportant = 0;