Improved Print Preview Toolbar

.  

Print preview is an extremely useful part of the MFC Doc/View architecture. However, the appearance of the print preview toolbar leaves a lot to be desired, and has not been updated since print preview was first added to MFC. The usual MFC-supplied preview button bar is shown below:

MFC default preview

Compare this with the replacement toolbar described in this article:

Improved preview

The replacement toolbar functions in exactly the same way as the default button bar, but has a more modern appearance. The normal text-based buttons are replaced with ownerdraw ones that use bitmaps for the various actions. Tooltips are available for the bitmapped buttons to help users make their selection.

To use the improved version requires only a few simple steps:

1. Add a few bitmap, string and dialog resources for the replacement toolbar (see the demo project for details)

2. Addition of a new CMyPreviewView class to control the preview toolbar, and a CMappedBitmapButton class to handle the buttons used. (Source files CMyPreviewView.cpp and CMappedBitmapButton.cpp)

3. Addition of a message handler inside your view class to produce print preview using the enhanced toolbar:


void CYourView::OnFileImprovedprintpreview() 
{
    // need to use CMyPreviewView class
    CPrintPreviewState* pState = new CPrintPreviewState;

    if (!DoPrintPreview(IDD_PREVIEW, this, RUNTIME_CLASS(CMyPreviewView), pState))
    {
        TRACE0("Error: OnFileImprovedprintpreview failed.\n");
        AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
        delete pState; // preview failed to initialize, delete State now
    }
}

The demo project (VC6) shows what needs to be done, and includes the various resources that must be added. The demo program allows you to compare the default and improved print preview toolbars in a simple application built around a CEditView window.

Download demo project - 56 KB



Comments

  • Toolbar & Menubar with CFormView

    Posted by Legacy on 09/06/2002 12:00am

    Originally posted by: Sree

    I have a CFormView based SDI app and when i pass the "this" pointer of the view to the PrintPreview class, the preview shows the toolbar and menubar also. how to hide them ?

    Reply
  • It works!

    Posted by Legacy on 08/21/2001 12:00am

    Originally posted by: Karoly Arnhoffer

    I tried this prview class, ant it works fine. I think it's much better than the old one. My question is whether it is possible to display more than two pages on the preview, or the whole print preview depends on version of VCPP. (Cos I'd like to use the frameworks, its good for me. I find difficult to prepare an own previewing mechanism.)

    Arnhoffer Karoly
    ak123@hszk.bme.hu

    Reply
  • EXCELLENT, BUT...

    Posted by Legacy on 06/27/2001 12:00am

    Originally posted by: J. H. Paul

    It's an excellent work but can anybody know how to do printing setup in the preview?
    Thank you

    Reply
  • Toolbar doesnt appear

    Posted by Legacy on 06/17/1999 12:00am

    Originally posted by: Paul Nadin

    I am trying to implement Print Preview on a set of CListView derived classes but have found it doesnt work properly.(for me)

    I cant get the default toolbar to appear so I tried your code as a possible fix to my problem, but without success.

    The Preview pane displays OK but without the expected preview toolbar. The framework hides my menu and toolbar but leaves a gap between the preview pane and the window titlebar showing the list control headers from behind. The window behaves as though the list control was in the foreground despite being hidden by the Preview Pane.

    anyone know what I'm doing wrong ?

    --
    Regards,
    Paul

    Reply
  • Great! But...

    Posted by Legacy on 04/20/1999 12:00am

    Originally posted by: yasuhiko yoshimura

    This is greate code.
    But would you please make it more tendy like the toolbar of Word97's preview?

    Thanks.

    y. yoshimura

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: January 7, 2015 The Flash Visionary Chat series of webinars brings together IT and business leaders as well as thought leading industry analysts to discuss how the flash revolution is eradicating inefficiency, unleashing innovation, and accelerating businesses. Join us for this episode where we are excited to host not only the 451 Research, who share their recent industry research, but also one of our top customers, who will share their perspective on the disruptive power of flash …

  • The 3rd Platform of computing, based around the four pillars of mobile computing, social media, big data and analytics, and cloud, is redefining what IT infrastructure needs to provide. Endpoint solutions must meet not only traditional data protection requirements, but also a new set of requirements driven by the explosion in mobile computing. This IDC white paper explores the customer challenges associated with safeguarding data residing on various endpoint devices, including laptops, tablets, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date