Solved

Setting Orientation using CPageSetupDialog  class

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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