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
Solved

Programatically Force Landscape Printer Orientation

Posted on 1998-02-23
2
504 Views
Last Modified: 2013-12-03
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!
0
Comment
Question by:eematt
2 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 150 total points
ID: 1411483
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
 
WINDOWS        | WINDOWS NT
 

---------------------------------------------------------------------
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
---------------------------------------------------------------------
 
SUMMARY
=======
 
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.
 
MORE INFORMATION
================
 
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.
            ::GlobalUnlock(m_hDevMode);
            }
        }
    }
 
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()
function.
 
 
Copyright Microsoft Corporation 1995.


 

0
 

Author Comment

by:eematt
ID: 1411484
Thanks Mike!
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

Suggested Solutions

Title # Comments Views Activity
Table Size and Indexes in SQL Server 6 26
Having Trouble with MS Access 2010 CommandBars 19 104
Need example 5 122
Please explain "Multi-Tenant Services" 5 99
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
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 …

839 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