BOOL CTestsdiView::ShowBmp(HDC hdc, char *strFileName, int xDst, int yDst, int dxDst, int dyDst)
{
FILE *fp;
BITMAPFILEHEADER bf;
LPBITMAPINFOHEADER lpbi;
DWORD dwImgSize;
int w,h;
HANDLE hFile;
int n;
n=Bmpname.Replace("\\", "\\\\");
// Open the existing file.
hFile = CreateFile( Bmpname, // open the BitMap file
GENERIC_READ,
0, // not share
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
//fail to open file
if (hFile == INVALID_HANDLE_VALUE)
{
return NULL;
}
BITMAPFILEHEADER bmfHeader;
DWORD nFileLen,dwBytesRead;
nFileLen = GetFileSize (hFile, NULL) ; //get the length of the file
//Check hDIB,if hDIB is null,exit the function
if(hDIB == NULL)
return bsuccess;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
//nColors is the factual color num
int nColors = bmInfo.bmiHeader.biClrUsed ?
bmInfo.bmiHeader.biClrUsed : 1 << bmInfo.bmiHeader.biBitCount;
//16 bit or 24 bit or 32 bit clearly color
if( bmInfo.bmiHeader.biBitCount > 8 )
lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors +
bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
//Other color
else
lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
// select the palette into a device context and realize it
if( pPal && (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) )
{
pDC->SelectPalette(pPal, FALSE);
pDC->RealizePalette();
}
int DisplayDib (HDC hdc, HBITMAP hBitmap, int x, int y,
int cxClient, int cyClient,
WORD wShow, BOOL fHalftonePalette)
{
BITMAP bitmap ;
HDC hdcMem ;
int cxBitmap, cyBitmap, iReturn ;