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: June 23, 2015 Business transformation is not just important, it is vital to the success of all organizations in the 21st century marketplace. How IT approaches and executes the move from cost center to revenue contributor will not only transform the IT organization, it will change how companies retain competitive advantage and meet the requirements of internal and external customers. This shift in thinking is not new, but actualizing it is. Check out this eSeminar to learn the …

  • The nature of the financial services industry places a myriad of international compliance requirements on a company's IT team, as well as an expectation by its customers to deliver the high test levels of performance and reliability. To survive and thrive, businesses in the industry must not only keep pace with customer demand but gain competitive advantage. Those demands mean the IT team must be at the forefront of adopting emerging technologies

Most Popular Programming Stories

More for Developers

RSS Feeds

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