|
Visual C++关键字导航 |
VC.NET 图像 帮助文档 OpenGL WinSockets 滤镜 COM/ATL 界面 多媒体 数据库 网络 MFC 文件 硬件 窗体 |
/* //打印或者在屏幕上画位图 //pDC 打印机或者屏幕dc指针 iLogPixelX iLogPixelY |
iLogPixelX=DC.GetDeviceCaps(LOGPIXELSX); iLogPixelY=DC.GetDeviceCaps(LOGPIXELSY); strFileName BMP文件 */ void DrawBMP(CDC* pDC,int iLogPixelX,int iLogPixelY,const char *strFileName) { CDC MemDC; // 内存设备环境指针,在视的整个存在过程都将存在 CBitmap Bitmap,*pOldBmp; CRect Source, Dest; // 记录源位图尺寸和最终显示尺寸 BITMAP bm; if(MemDC.GetSafeHdc() == NULL) { HBITMAP hbitmap=(HBITMAP)LoadImage(0,strFileName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE); Bitmap.Attach(hbitmap); MemDC.CreateCompatibleDC(pDC); Bitmap.GetObject(sizeof(bm),&bm); pOldBmp=MemDC.SelectObject(&Bitmap); Source.top=0; Source.left=0; Source.right= bm.bmWidth; Source.bottom = bm.bmHeight; Dest = Source; } pDC->DPtoLP(&Dest); if(pDC->IsPrinting()) { Dest.left=(int)(Dest.left*((double)pDC->GetDeviceCaps(LOGPIXELSX))/iLogPixelX); Dest.right=(int)(Dest.right*((double)pDC->GetDeviceCaps(LOGPIXELSX))/iLogPixelX); Dest.top=(int)(Dest.top*((double)pDC->GetDeviceCaps(LOGPIXELSY))/iLogPixelY); Dest.bottom=(int)(Dest.bottom*((double)pDC->GetDeviceCaps(LOGPIXELSY))/iLogPixelY); } pDC->StretchBlt(Dest.left, Dest.top, Dest.right, Dest.bottom, &MemDC, Source.left, Source.top, Source.right,Source.bottom, SRCCOPY); MemDC.SelectObject(pOldBmp); Bitmap.DeleteObject(); MemDC.DeleteDC(); return; } |
char *str = new char[256]; ::GetModuleFileName(NULL,str,MAX_PATH); //str即为所求 delete []str; str=NULL; |