Programatically Force Landscape Printer Orientation

I am using VC++ 5.0
I am using MFC creating a 32 bit EXE
I am using the standard printing capabilities generated by App Studio.

I am trying to programatically force the default Printer Device into Landscape Orientation.  
(and then back to it's previous state after I have printed)

The coder who solves my quandry not only gets my 150 points but my fond admiration and appreciation!
Who is Participating?
MikeP090797Connect With a Mentor Commented:
Here is an article form the KB:
PSS ID Number: Q126897
Article last modified on 08-17-1995
1.50 1.51 1.52 | 1.00 2.00 2.10

The information in this article applies to:
 - The Microsoft Foundation Classes (MFC), included with:
    - Microsoft Visual C++ for Windows, versions 1.5, 1.51, 1.52
    - Microsoft Visual C++, 32-bit Edition, versions 2.00, 2.10
To change the default printer settings in an MFC application, you must
retrieve the system default settings in a CWinApp derived object and modify
those defaults before a print job is invoked.
Default printer driver settings in an MFC application are maintained in the
CWinApp object. These settings take the form of the following two protected
member variables:
 - m_hDevMode, which is a handle to a global memory object that contains a
   DEVMODE structure.
 - m_hDevNames, which is a handle to a global memory object that contains a
   DEVNAMES structure.
These variables are initialized to NULL by MFC when the application starts.
The first time a print operation is invoked, the global default printer
settings are retrieved in these variables. All subsequent print operations
in the application will take their printer settings from these variables.
To set an application's default printer settings to something different
from the system defaults, the application must retrieve the system defaults
before a print operation and modify the values in the appropriate member
variable in the CWinApp derived object. To retrieve the system defaults,
you can use the CWinApp::GetPrinterDeviceDefaults() function.
Sample Code
For example, if you want to set the orientation in your application to
landscape mode, you could use a function similar to the following where
CMyWinApp is a class derived from the CWinApp class:
void CMyWinApp::SetLandscape()
    // Get default printer settings.
    PRINTDLG   pd;
    pd.lStructSize = (DWORD) sizeof(PRINTDLG);
    if (GetPrinterDeviceDefaults(&pd))
        // Lock memory handle.
        DEVMODE FAR* pDevMode =
            (DEVMODE FAR*)::GlobalLock(m_hDevMode);
        if (pDevMode)
            // Change printer settings in here.
            pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
            // Unlock memory handle.
If you want landscape to be the default orientation for the application,
you would call this function before any print job was invoked. A good place
to do this would be in your CWinApp derived class's InitInstance()
Copyright Microsoft Corporation 1995.


eemattAuthor Commented:
Thanks Mike!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.