Print Preview Enhancements | CodeGuru

Print Preview Enhancements

New users of this class will have to visit Robin’s article for the relevant download material and then update the .cpp/.h files with the versions provided in this article. Old users of the class can just replace their existing .cpp/.h files with these. Overview of New Functionality This is an update of the nice class […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 24, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

New users of this class will have to visit Robin’s article for the relevant
download material and then update the .cpp/.h files with the versions provided in this
article. Old users of the class can just replace their existing .cpp/.h files with these.

Overview of New Functionality

This is an update of the nice class provided in Robin’s article and includes the following features:

  • The print preview will now never show empty preview pages unless the user views 2 pages of
    output when only 1 is available.
  • Print preview will now respond to WM_MOUSEWHEEL messages appropriately. In “zoom out” mode, it
    will scroll you through the pages of output. In “zoom in” mode, it will scroll the output page up/down.

Implementation Details

For the mouse wheel to work correctly, you will have to override your
CMainFrame::PreTranslateMessage() function as follows:

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
 // TODO: Add your specialized code here and/or call the base class
 if (pMsg->message == WM_MOUSEWHEEL)
 {
  CView *pView = GetActiveView() ;
  if (pView != NULL)
   pView->SendMessage(WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam) ;
 }

 // call the base class here
}

This is required because in print preview mode, the WM_MOUSEWHEEL messages go to
the CDialogBar in the window and not directly to the view. This was the only way
I could find of easily getting these messages to the CMyPreviewView window.

Advertisement

Downloads

Download source – 6 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.