附件下載:http://files.cnblogs.com/mengdejun/print.ziphtml
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/96,yLogPixPerInch*winSize.cy/96); CView::OnPrepareDC(pDC, pInfo); }
MFC橫向打印spa
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); }