Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

Force landscape orientation in printer setup

Hi to all,

How can I force landscape orientation when I display printer setup dialog box ?

Here's my printer setup function :

BOOL CMyPrintClass::PrintSetup(HWND hParent, BOOL bDefault)
 {
  PRINTDLG stPD;

  memset(&stPD, 0, sizeof(stPD));

  stPD.lStructSize = sizeof(stPD);
  stPD.hwndOwner = hParent;
  stPD.Flags = PD_ALLPAGES | PD_DISABLEPRINTTOFILE |
                     PD_NOPAGENUMS | PD_NOSELECTION |                      PD_TURNDC;

  if (bDefault)
   {
    stPD.Flags |= PD_RETURNDEFAULT;
   }

  BOOL bRet = PrintDlg(&stPD);

  if (bRet == FALSE && CommDlgExtendedError()) return FALSE;

  if (bRet == FALSE && !CommDlgExtendedError()) return TRUE;

  if (m_hPrintDC) DeleteDC(m_hPrintDC);

  m_hPrintDC = stPD.hDC;

  return (m_hPrintDC != NULL);
 }

Here's my print function (partial only) :

BOOL CMyPrintClass::Print(HWND hParent, LPCTSTR lpszDocName)
 {
  if (!m_hPrintDC && !PrintSetup(hParent,TRUE)) return FALSE;

  // Printing is done here with m_hPrintDC as print context
 }
Avatar of nietod
nietod

You need to allocate a device mode structure (DEVMODE) and indicate that the dvice is in landscape mode.

continues.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

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
You need to allocate the memory using GlobalAlloc(sizeof(DEVMODE)) (unfortunately) and store the handle to the memory in the PRINTDLG's hDevMode member.  Then lock the memory with GlobalLock()  Clear the memory to 0's if not done by GlobalAlloc()  (there is a flag to due this from GlobalAlloc()).  You then need to set  the dmSize member to sizeof(DEVMODE).  Then to place the pritner in landscape mode, set the DM_ORIENTATION bit flag in the dmFields member to 1.  This indicates that the DEVMODE is specifing the paper orientation.  (These bit fields allow you to specify certain properties and let the rest default, which saves you from having to specify them all..)  then set the dmOrientation member to DMORIENT_LANDSCAPE.  set any other features you wish.  Then unlock the memory and call PrintDlg().

The orientation should be landscape.

However, after PrintDlg() is through, at some point you need to delete the DEVMODE and the DEVNAMES structures that are returned in the PRINTDLG's hDevMode and hDevNames members.  This has nothing to do with what I told you above.  If you don't allcoate memory for these, then PrintDlg() does, so in either case, you must delete this memory in the end (using GlobalFree()).
Avatar of mike_marquet

ASKER

Thanks.