Microsoft KB Archive/214617

= How to change the page orientation without interacting with the common Print dialog box in Visual C++ =

Article ID: 214617

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q214617

<div class="summary_section">

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.

<div class="moreinformation_section">

MORE INFORMATION
The following files are available for download from the Microsoft Download Center:

Visual C++ 6.0
Download Mfcdvmd.exe now

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Visual C++ .NET
Download Mfcdvmdvcnet.exe now

Release Date: August 14, 2002

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

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.

<div class="references_section">