The function shown below sets the orientation of the paper for a printer. Call this function before CView::OnFilePrint() and CView::OnFilePrintPreview() calls.
Code:BOOL SetOrientation(BOOL bLandFl) { PRINTDLG pd; pd.lStructSize=(DWORD)sizeof(PRINTDLG); BOOL bRet=GetPrinterDeviceDefaults(&pd); if(bRet) { // protect memory handle with ::GlobalLock and ::GlobalUnlock DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(m_hDevMode); // set orientation to landscape if(bLandFl) pDevMode->dmOrientation=DMORIENT_LANDSCAPE; else pDevMode->dmOrientation=DMORIENT_PORTRAIT; ::GlobalUnlock(m_hDevMode); } else { CString s; s.LoadString(IDS_STRING34116); //Failed to select the orientation of the paper for the printer AfxMessageBox(s); } return bRet; }




Reply With Quote