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
 }
mike_marquetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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

continues.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
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()).
0
mike_marquetAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.