Solved

Setting Orientation using CPageSetupDialog  class

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 178
Get filename and folder into excel 7 74
Unix / Linux grid computing 5 157
method notes when mouse over in eclipse 5 87
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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