HBITMAP *hBitmap; //定义位图对象句柄 hBitmap=(HBITMAP*)::LoadImage( AfxGetInstanceHandle(),"tmp.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE); CBitmap bmp; CDC dcMemory; if (bmp.Attach(hBitmap)) { // Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); // Create an in-memory DC compatible with the // display DC we're using to paint dcMemory.CreateCompatibleDC(&memDC); // Select the bitmap into the in-memory DC CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp); // Find a centerpoint for the bitmap in the client area CRect rect; // Copy the bits from the in-memory DC into the on- // screen DC to actually do the painting. Use the centerpoint // we computed for the target offset. memDC.BitBlt(1,200, bmpInfo.bmWidth*25, bmpInfo.bmHeight*25, &dcMemory,0, 0, BLACKNESS); dcMemory.SelectObject(pOldBitmap); }
hBitmap=(HBITMAP*)::LoadImage( AfxGetInstanceHandle(),"tmp.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
CBitmap bmp;
CDC dcMemory;
if (bmp.Attach(hBitmap))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we're using to paint
dcMemory.CreateCompatibleDC(&memDC);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
// Find a centerpoint for the bitmap in the client area
CRect rect;
// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
memDC.BitBlt(1,200, bmpInfo.bmWidth*25, bmpInfo.bmHeight*25, &dcMemory,0, 0, BLACKNESS);
dcMemory.SelectObject(pOldBitmap);
}
按下面的做OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
//设定自动用户调节比例的映射模式
pDC->SetMapMode(MM_ANISOTROPIC);
CRect rcClient;
GetClientRect(rcClient);
CSize size(rcClient.right,rcClient.right);
//设定当前的窗口
pDC->SetWindowExt(size);
//获取当前显示设备(显示器/打印机)每英寸中包含的象素点个数
int xLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInce = pDC->GetDeviceCaps(LOGPIXELSY);
int xExt;
int yExt;
xExt = size.cx * xLogPixPerInch / 96 ; // 96 为屏幕显示的每英寸象素数目
yExt = size.cy * yLogPixPerInce / 96 ;
pDC->SetViewportExt(xExt,yExt);
}
OK 再试试吧,搞定了