附件下载:http://files.cnblogs.com/mengdejun/print.zip
void CPrintView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
//设置打印环境坐标转换
pDC->SetMapMode(MM_ANISOTROPIC);
int screenwidth_real=GetSystemMetrics(SM_CXSCREEN);
int screenheight_real=GetSystemMetrics(SM_CYSCREEN);
CSize winSize=CSize(screenwidth_real,screenheight_real);
//设置窗口大小
pDC->SetWindowExt(winSize);
long xLogPixPerInch,yLogPixPerInch;
//获得设备坐标即每英寸多少像素
xLogPixPerInch=pDC->GetDeviceCaps(LOGPIXELSX);
yLogPixPerInch=pDC->GetDeviceCaps(LOGPIXELSY);
//设置视口大小 96%
pDC->SetViewportExt(xLogPixPerInch*winSize.cx/,yLogPixPerInch*winSize.cy/);
CView::OnPrepareDC(pDC, pInfo);
}
MFC横向打印
BOOL CPrintView::OnPreparePrinting(CPrintInfo* pInfo)
{
//下列语句使打印机默认横向打印
LPDEVMODE lpDevMode;
PRINTDLG pd=pInfo->m_pPD->m_pd;
if(AfxGetApp()->GetPrinterDeviceDefaults(&pd)){
lpDevMode=(LPDEVMODE)GlobalLock(pd.hDevMode);
if(lpDevMode){
lpDevMode->dmPaperSize=DMPAPER_A4;
lpDevMode->dmOrientation=DMORIENT_LANDSCAPE;//横向打印
}
GlobalUnlock(pd.hDevMode);
}
//上述语句使打印机默认横向打印
return DoPreparePrinting(pInfo);
}