Link to home
Start Free TrialLog in
Avatar of mgordon
mgordon

asked on

Forcing landscape orientation

How can I force Print Preview  to show a particular view in landscape orientation without user intervention?
(and Print to print it, naturally!)
Mike.
ASKER CERTIFIED SOLUTION
Avatar of Wyn
Wyn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wyn
Wyn

If you use MFC ,Use a CPrintDialog:

CPrintDialog PrintDialog(FALSE);
   
 
AfxGetApp()->GetPrinterDeviceDefaults(&PrintDialog.m_pd);

DEVMODE  FAR *lpDevMode  = (DEVMODE  FAR *)  
::GlobalLock(PrintDialog.m_pd.hDevMode);
//set mode
lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
 
::GlobalUnlock(PrintDialog.m_pd.hDevMode);

Then create a CDC and attach with PrinterDC:
  CDC DC;
  DC.Attach(PrintDialog.GetPrinterDC());
 
//Then set the document info
  DOCINFO di;
  CString strTitle;
  memset (&di,0,sizeof(DOCINFO));
  strTitle.LoadString (AFX_IDS_APP_TITLE);
  di.cbSize = sizeof(DOCINFO);
  di.lpszDocName = strTitle;
  strTitle.Empty();

//start the actual printing
  DC.StartDoc (&di);
  DC.StartPage ();

 
//printing here.....
DC.TextOut();

.......detach latter.

All..
Here is working code to set landscape mode:

PrintDialog.m_pd.hDevMode = ::GlobalAlloc( GHND, sizeof(DEVMODE) );
  DEVMODE * devMode = (DEVMODE *) ::GlobalLock(     PrintDialog.m_pd.hDevMode );
  devMode->dmSize = sizeof(DEVMODE);
  devMode->dmOrientation = DMORIENT_LANDSCAPE;
  devMode->dmFields = DM_ORIENTATION;
  ::GlobalUnlock( devMode );  
Finally,this article will help you alot:

HOWTO: Modify Printer Settings with DocumentProperties()
http://support.microsoft.com/support/kb/articles/Q167/3/45.ASP
Avatar of mgordon

ASKER

For Wyn.
The first 7 lines of your 4.40 (first) answer did the trick wonderfully well.
Thanks, Mike Gordon.