Using Print Preview with ATL
The CPrintPreviewFrameImpl class makes it easy to use print preview in ATL. It can be used to add print preview capabilities to ATL windows. It is a template class that takes the base window class as a template parameter. The CPrintPreviewFrameImpl class contains a print preview model, viewport, and controller. It takes care of creating and initializing the print preview model, viewport, and controller objects.
To use the CPrintPreviewFrameImpl class, just instantiate it with an ATL-based window class as the first template parameter. The CPrintPreviewFrameImpl class handles both the print and print preview commands. The command identifiers for both commands can optionally be passed in as template parameters. The default command identifiers are IDC_SFL_FILE_PRINT and IDC_SFL_FILE_PRINT_PREVIEW. The CPrintPreviewFrameImpl class defines the virtual method BeginPrintPreview(), which is called when a print preview command is received. The BeginPrintPreview() method takes care of creating and showing the print preview window. A corresponding EndPrintPreview() method closes the print preview window. The OnBeginPreview() and OnEndPreview methods give derived classes an opportunity to perform custom tasks before the print preview window is shown and after it is closed.
The CPrintPreviewFrameImpl class is actually an abstract base class. It defines the pure virtual method GetCurrentPrintable(), which must be implemented by derived classes. Rather than hardwiring into the framework knowledge of which object to print, as MFC does with Document/View, the GetCurrentPrintable() method allows the CPrintPreviewFrameImpl class to avoid making any assumptions about what to print.