怎样动态的显示磁盘上的一个图片? API即可:LoadImage 载入图片BitBlt 画 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //pDC 绘图dc pDC=GetDC();//FileName "c:\\bmp\\cc.bmp"//x,y,显示在dc中的位置//width,height,想显示的大小BOOL BmpRead(CDC *pDC,char *FileName,int x,int y,int width,int height){ BITMAPINFOHEADER bi; int dwOffset; int i; CFile OpenFile; LOGPALETTE *lp; BYTE PaletteBuffer[1024]; CPalette cp,*OldCp; BYTE *pBuf; BITMAPINFO *bf; if(OpenFile.Open (FileName,CFile::modeRead)==NULL)return FALSE; OpenFile.Seek(14,CFile::begin); OpenFile.Read(&bi,40); if(bi.biSizeImage==0)bi.biSizeImage=(long)bi.biWidth*bi.biHeight*bi.biBitCount/8; if(bi.biBitCount<=8) { lp =(LOGPALETTE *)new BYTE[sizeof(LOGPALETTE) +(int)bi.biClrUsed* sizeof(PALETTEENTRY)]; lp->palVersion=0x300; lp->palNumEntries=(int)bi.biClrUsed; OpenFile.Read(PaletteBuffer,(int)bi.biClrUsed*4); OpenFile.Close(); for (i = 0; i < (int)bi.biClrUsed; i++){ lp->palPalEntry[i].peRed = PaletteBuffer[4*i+2]; lp->palPalEntry[i].peGreen = PaletteBuffer[4*i+1]; lp->palPalEntry[i].peBlue = PaletteBuffer[4*i+0]; lp->palPalEntry[i].peFlags = 0; } cp.CreatePalette(lp); OldCp=pDC->SelectPalette(&cp,FALSE); pDC->RealizePalette(); } else OpenFile.Close(); if(bi.biBitCount<=8) bf=(BITMAPINFO*)new BYTE[bi.biSize + bi.biClrUsed *4]; else bf=(BITMAPINFO*)new BYTE[bi.biSize]; OpenFile.Open (FileName, CFile::modeRead); OpenFile.Seek(14,CFile::begin); if(bi.biBitCount<=8) OpenFile.Read(bf,(int)bi.biClrUsed *4+bi.biSize); else OpenFile.Read(bf,bi.biSize); OpenFile.Close(); pBuf=new BYTE[bi.biSizeImage]; OpenFile.Open(FileName,CFile::modeRead); if(bi.biBitCount<=8) dwOffset=54+bi.biClrUsed*4; else dwOffset=54; OpenFile.Seek(dwOffset,CFile::begin); OpenFile.Read(pBuf,bi.biSizeImage); OpenFile.Close(); x=x+(width-(int)bi.biWidth)/2; y=y+(height-(int)bi.biHeight)/2; StretchDIBits( pDC->m_hDC, // handle to device context 0, // x-coordinate of upper-left corner of dest. rectangle 0, // y-coordinate of upper-left corner of dest. rectangle width, // width of destination rectangle height, // height of destination rectangle 0, // x-coordinate of upper-left corner of source rectangle 0, // y-coordinate of upper-left corner of source rectangle bi.biWidth, // width of source rectangle bi.biHeight, // height of source rectangle pBuf, // address of bitmap bits (BITMAPINFO *)bf, // address of bitmap data DIB_RGB_COLORS, // usage flags SRCCOPY // raster operation code );if(bi.biBitCount<=8){ pDC->SelectPalette(OldCp,FALSE); cp.DeleteObject(); delete lp; } delete pBuf; delete bf; return TRUE;} 窗体半透明 键盘、鼠标等的驱动程序(hid) 深入浅出MFC第十一章重绘效率的问题 请教 微软活动目录编程 - 4点内容 MFC CString.Format问题 利用DAO技术执行SQL语句查询数据库时的出错问题,棘手~~~~ 如何获得磁盘剩余空间? 谁能提供能够播放小提琴的midi 源程序 ★★★快来抢300分★★★:谁有《visual c++ 6.0经典实例大制作》中实例的源代码? 程序最小化到任务栏时,闪烁 请问如何将COleDateTime类型将转化为Const Char * ? 如何查询ODBC数据源的信息?
//FileName "c:\\bmp\\cc.bmp"
//x,y,显示在dc中的位置
//width,height,想显示的大小
BOOL BmpRead(CDC *pDC,char *FileName,int x,int y,int width,int height)
{
BITMAPINFOHEADER bi;
int dwOffset;
int i;
CFile OpenFile;
LOGPALETTE *lp;
BYTE PaletteBuffer[1024];
CPalette cp,*OldCp;
BYTE *pBuf;
BITMAPINFO *bf;
if(OpenFile.Open (FileName,CFile::modeRead)==NULL)return FALSE;
OpenFile.Seek(14,CFile::begin);
OpenFile.Read(&bi,40);
if(bi.biSizeImage==0)bi.biSizeImage=(long)bi.biWidth*bi.biHeight*bi.biBitCount/8;
if(bi.biBitCount<=8)
{
lp =(LOGPALETTE *)new BYTE[sizeof(LOGPALETTE) +(int)bi.biClrUsed* sizeof(PALETTEENTRY)];
lp->palVersion=0x300;
lp->palNumEntries=(int)bi.biClrUsed;
OpenFile.Read(PaletteBuffer,(int)bi.biClrUsed*4);
OpenFile.Close();
for (i = 0; i < (int)bi.biClrUsed; i++){
lp->palPalEntry[i].peRed = PaletteBuffer[4*i+2];
lp->palPalEntry[i].peGreen = PaletteBuffer[4*i+1];
lp->palPalEntry[i].peBlue = PaletteBuffer[4*i+0];
lp->palPalEntry[i].peFlags = 0;
}
cp.CreatePalette(lp);
OldCp=pDC->SelectPalette(&cp,FALSE);
pDC->RealizePalette();
}
else
OpenFile.Close();
if(bi.biBitCount<=8)
bf=(BITMAPINFO*)new BYTE[bi.biSize + bi.biClrUsed *4];
else
bf=(BITMAPINFO*)new BYTE[bi.biSize];
OpenFile.Open (FileName, CFile::modeRead);
OpenFile.Seek(14,CFile::begin);
if(bi.biBitCount<=8)
OpenFile.Read(bf,(int)bi.biClrUsed *4+bi.biSize);
else
OpenFile.Read(bf,bi.biSize);
OpenFile.Close(); pBuf=new BYTE[bi.biSizeImage]; OpenFile.Open(FileName,CFile::modeRead);
if(bi.biBitCount<=8)
dwOffset=54+bi.biClrUsed*4;
else
dwOffset=54;
OpenFile.Seek(dwOffset,CFile::begin);
OpenFile.Read(pBuf,bi.biSizeImage);
OpenFile.Close(); x=x+(width-(int)bi.biWidth)/2;
y=y+(height-(int)bi.biHeight)/2;
StretchDIBits(
pDC->m_hDC, // handle to device context
0, // x-coordinate of upper-left corner of dest. rectangle
0, // y-coordinate of upper-left corner of dest. rectangle
width, // width of destination rectangle
height, // height of destination rectangle
0, // x-coordinate of upper-left corner of source rectangle
0, // y-coordinate of upper-left corner of source rectangle
bi.biWidth, // width of source rectangle
bi.biHeight, // height of source rectangle
pBuf, // address of bitmap bits
(BITMAPINFO *)bf, // address of bitmap data
DIB_RGB_COLORS, // usage flags
SRCCOPY // raster operation code
);if(bi.biBitCount<=8)
{
pDC->SelectPalette(OldCp,FALSE);
cp.DeleteObject();
delete lp;
}
delete pBuf;
delete bf;
return TRUE;
}