Solved

Setting Orientation using CPageSetupDialog  class

Posted on 2003-10-21
6
566 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video discusses moving either the default database or any database to a new volume.

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now