?
Solved

Force landscape orientation in printer setup

Posted on 2000-01-14
4
Medium Priority
?
588 Views
Last Modified: 2013-12-03
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
 }
0
Comment
Question by:mike_marquet
  • 3
4 Comments
 
LVL 22

Expert Comment

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

continues.
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 2352586
You need to allocate a device mode structure (DEVMODE) and indicate that the dvice is in landscape mode.

continues.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2352607
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
 

Author Comment

by:mike_marquet
ID: 2352777
Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question