Solved

Setting Orientation using CPageSetupDialog  class

Posted on 2003-10-21
6
586 Views
Last Modified: 2013-11-20
How can we set Orientation(Landscape or Portrait) using CPageSetupDialog.
How can we know which orientation is actually been selected.
0
Comment
Question by:kalyanreddy_kk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9590372
See the sample code in MSDN topic CWinApp::GetPrinterDeviceDefaults.

    http://msdn.microsoft.com/library/en-us/vclib/html/_mfc_cwinapp.3a3a.getprinterdevicedefaults.asp
    {{ link added -- DR / EE PE }}
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9591189
>> How can we set Orientation(Landscape or Portrait) using CPageSetupDialog.

After construction, you can access the m_psd member variable. Allocate a DEVMODE structure with GlobalAlloc(), set the fields properly (it seems you're interested in dmOrientation only, but I think you'll have to fill the rest as well), put the handle in m_psd.hDevMode and call DoModal(). Remember to free that memory when you're done.

>> How can we know which orientation is actually been selected.

After DoModal(), call GetDevMode(), read the dmOrientation field (don't forget to call GlobalUnlock() on the returned pointer)

0
 

Expert Comment

by:ViralPurohit
ID: 9601275
Code Snippet from my application, Hope this helps

BOOL CMyApp::SetPrinterOrientation(BOOL bLandscape)
{
  if (!m_hDevMode) return FALSE;

  DEVMODE *pstDevMode = (DEVMODE *)GlobalLock(m_hDevMode);

  pstDevMode->dmFields |= DM_ORIENTATION;

  pstDevMode->dmOrientation = bLandscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;

  GlobalUnlock(m_hDevMode);

  return TRUE;
}


/// Or you can use this function
/// param can be DMORIENT_LANDSCAPE
void CMyApp::SetPrinterOrientation(int nOri)
{
      PRINTDLG   pd;
      
      pd.lStructSize = (DWORD) sizeof(PRINTDLG);
      if (GetPrinterDeviceDefaults(&pd)){
            DEVMODE FAR* pDevMode = (DEVMODE FAR*)::GlobalLock(m_hDevMode);
             
            if (pDevMode){
                  pDevMode->dmOrientation = nOri;
                  
                  ::GlobalUnlock(m_hDevNames);
                  ::GlobalUnlock(m_hDevMode);
            }
      }
}


Regards,
Viral Purohit
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

726 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