??
解决方案 »
- 求解: 成员变量的值会自动改变,为什么会这样?
- 向各位请教关于网狐棋牌,登录界面密码加密方式的问题!!!
- vfw支持哪些视频格式?
- 如何制作ActiveX的本地安装包?
- 如何找到系统启动时候所需要的文件?
- 请问怎样用recvfrom接收未知数目的响应包?
- 请问Dialog下怎么显示位图,为什么这样不行
- 高手请进:100分求如何得到word文档的第一页!!!
- 为什么我的程序如果的开头没有# define WINVER 0x0500 我的头文件里的声明就报错呢?
- 请教各位高手,如何利用VC++开发所见即所得的打印程序,请详细一点,谢谢!(在线等待)
- 怎么转换BMP图象格式
- 请问如何给工具条加TOOLTIP
你也可以从程序的资源中导入
下面的代码显示了从文件读入位图并显示BOOL CSplashWnd::LoadBmpImage(LPCTSTR lpszBmpFile, CBitmap& bitmap)
{
CFile file; if( !file.Open(lpszBmpFile, CFile::modeRead) )
return FALSE; long nFileLen = file.GetLength();
BITMAPFILEHEADER bmfHeader; // read file header
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return FALSE; // file type should be 'bm'
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return FALSE; // get length of the remainder of the file and allocate memory
HGLOBAL hDib=::GlobalAlloc(GMEM_FIXED, nFileLen);
if (hDib == NULL)
return FALSE; // read the remainder of the bitmap file.
if ( file.ReadHuge((LPSTR)hDib, nFileLen - sizeof(BITMAPFILEHEADER)) != (nFileLen - sizeof(BITMAPFILEHEADER)) )
{
::GlobalFree(hDib);
return FALSE;
} CPalette* pPal = new CPalette();
BITMAPINFO &bmInfo=*(LPBITMAPINFO)hDib; int nColors = bmInfo.bmiHeader.biClrUsed ? bmInfo.bmiHeader.biClrUsed : 1 << bmInfo.bmiHeader.biBitCount; LPVOID lpDibBits; // pointer to dib bits
if( bmInfo.bmiHeader.biBitCount> 8 )
lpDibBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors +
bmInfo.bmiHeader.biClrUsed) +
((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
else
lpDibBits = (LPVOID)(bmInfo.bmiColors + nColors); // create the logical palette
CClientDC dc(NULL);
if( nColors <= 256 )
{
UINT nSize = sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * nColors;
LOGPALETTE* pLP= (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries = nColors; for(int i = 0; i < nColors; i++)
{
pLP->palPalEntry[i].peRed = bmInfo.bmiColors[i].rgbRed;
pLP->palPalEntry[i].peGreen = bmInfo.bmiColors[i].rgbGreen;
pLP->palPalEntry[i].peBlue = bmInfo.bmiColors[i].rgbBlue;
pLP->palPalEntry[i].peFlags = 0;
} pPal->CreatePalette(pLP); delete[] pLP;
}
else
pPal->CreateHalftonePalette(&dc); CPalette* pOldPalette = NULL;
if (pPal)
{
pOldPalette = dc.SelectPalette(pPal, FALSE);
dc.RealizePalette();
} BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDib; HBITMAP hBmp = CreateDIBitmap(dc.m_hDC, // handle to device context
&bmiHeader, // pointer to bitmap size and format data
CBM_INIT, // initialization flag
lpDibBits, // pointer to initialization data
&bmInfo, // pointer to bitmap color-format data
DIB_RGB_COLORS); // color-data usage bitmap.Attach(hBmp); if(pOldPalette)
dc.SelectPalette(pOldPalette, FALSE); ::GlobalFree(hDib); delete pPal; return TRUE;
}