|
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; |
原文轉自:http://www.anti-gravitydesign.com