Better Print Preview | CodeGuru

Better Print Preview

One of the biggest advantages to using the MFC document/view architecture is the Print Preview feature. However, this feature is sometimes far less than easy to understand and utilize to its fullest capacity. Therefore, in this article, I’m presenting some improvements to Print Preview that I developed while working on a recent project. The first […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 31, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

One of the biggest advantages to using the MFC document/view architecture is
the Print Preview feature. However, this feature is sometimes far less than
easy to understand and utilize to its fullest capacity. Therefore, in this
article, I’m presenting some improvements to Print Preview
that I developed while working on a recent project.

The first thing I did was to eliminate flicker from the preview dialog by
utilizing the BitBlt function. You can see an outline of the ExtPreviewView
class definition below. This class is derived from the MFC
CPreviewView class (described in detail in the MFC Technical Note 30).

The three protected members are used to hold the virtual viewport data.
These values are initialized when the InitVxPrintOffset function is called.
Therefore, you are able to create a bitmap on a memory DC which is compatible
with the Preview DC in MFC for high-speed drawing now that you can get the
maximum size of virtual paper.

// override MFC class
class ExtPreviewView : public CPreviewView
{
…
protected:
 // Original viewport point of memory DC
 CSize m_VxPrintOffset;
 CSize m_sizeVxVpExt, m_sizeVxWinExt;
public:
 void InitVxPrintOffset(CDC* pDC);
 …
 friend class CAdvancedPreviewView;
};

The second improvement I made was to add three additional zoom-in
levels.

#define ZOOM_IN_150     3
#define ZOOM_IN_200     4
#define ZOOM_IN_400     5

Caution!

You need to include the gafximpl.h
in order to incorporate into your project the source code supplied with this article.

This is how to configure Visual Studio so that it can locate this needed header file.

  1. On the Project menu, click Settings.
  2. In the Settings dialog box, select the C/C++ tab.
  3. Select Preprocessor from the Category drop-down list.
  4. The project-specific include paths are located in the Additional include
    directories edit box.

Downloads

Download demo project – 28 Kb
Download demo application – 15 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.