Changing the Page Orientation to Landscape Without Interacting with the Print Dialog Box in an MFC-Based Application

ID: Q214617


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0


SUMMARY

Default printing in MFC supports changing the page orientation (Portrait or Landscape) by interacting with the common Print dialog box. Sometimes, it may be necessary to change the page orientation at run time without interacting with the Print dialog box; for example, when changing the orientation to Landscape for printing a large report.

Mfcdvmd.exe is a sample that shows how the page orientation can be changed without interacting with the common Print dialog box. This is a self extracting .exe file.


MORE INFORMATION

The following files are available for download from the Microsoft Download Center. Click the file names below to download the files:


Mfcdvmd.exe

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address

http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.

Sample Functionality

First, the sample queries for the available printers, in the OnPrepareDC function of CMyPrintView. Then, the sample allocates memory using the queried PrinterInfo. This is done to query the name of the printer.

A member function ChangeDevMode() is added to CMyPrintView. The ChangeDevMode() function follows these three steps for obtaining and changing the DEVMODE buffer. The function takes a named printer and configures a DEVMODE to print in Landscape if it supports these features. The resulting DEVMODE is returned to the caller, that is the OnPrepareDC function. When OnPrepareDC is done with the DEVMODE buffer, it is responsible for freeing the memory.

The change in the page orientation can be verified either by printing on paper or by print-previewing. Even if the Print Setup dialog box is set to Portrait, the page will print with a Landscape orientation.

NOTE: To use the Print APIs, Winspool.h needs to be included.


REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

Q132239 TITLE : SAMPLE: Calling ExtDeviceMode/DeviceCapabilities in Win32s App
Q167345 HOWTO: Modify Printer Settings with DocumentProperties()

Additional query words: DEVMODE OnPrepareDC PrinterInfo orientation

Keywords : kbfile kbsample kbCmnDlgPrint kbMFC kbPrinting kbVC500 kbVC600
Version : winnt:5.0,6.0
Platform : winnt
Issue type :


Last Reviewed: December 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.