Printer Paper Oritentation problem!
Hi,
I have a MFC app which conatians a chart control. I want to print this chart to the printer. I can do it using inbuilt properties for the chart but only in portrait mode.
Is there a way to set the orientation of the printer to landscape before is start printing. I don't know any interface or classes that provide such functionality.
Please Help!!!
Re: Printer Paper Oritentation problem!
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;
}
Re: Printer Paper Oritentation problem!
I forgot to say that SetOrientation() function should be declared in your application class derrived from CWinApp. HGLOBAL m_hDevMode is protected member of the CWinApp class.