Objective Toolkit : Chapter 15 User Interface Extensions : Thumbnail Classes
Thumbnail Classes
Many Windows applications like Microsoft PowerPoint and Delrina WinFax support thumbnails. Thumbnails let the user preview a file without having to open it. Objective Toolkit provides thumbnail support through the document/view architecture.
Figure 123 – Example Thumbnail
A snapshot of the current view is stored at the beginning of the archive file when the document is serialized. A specialized File Open dialog displays the stored image of highlighted files to aid in file selection.
The thumbnail classes are designed to display the special images stored in archive files. They cannot be used to display images from other file formats.
The Thumbnail Classes
The following classes work together to provide Objective Toolkit thumbnail support. SECTNBitmap, SECTNDC, and SECTNFileDialog are usually transparent to your application, but you need to know how they function.
Figure 124 – Thumbnail Class Hierarchy
SECTNBitmap
SECTNBitmap is a CBitmap derivative that creates, saves, and displays thumbnail images.
SECTNDC
SECTNDC is a CDC derivative that is passed to your SECTNView’s OnDraw() method. The view draws the thumbnail image onto the SECTNDC. Objective Toolkit converts the image to an SECTNBitmap and then saves the image.
SECTNDocument
Class SECTNDocument is an optional CDocument derivative that stores an SECTNView thumbnail image during serialization and bypasses the thumbnail image when reading.
SECTNFileDialog
SECTNFileDialog uses a CFileDialog derivative to display a thumbnail. SECTNFileDialog also automatically reads and displays the thumbnail image when the user clicks a file name in the dialog.
SECTNView
SECTNView is a CView derivative that can automatically generate a thumbnail by drawing onto an SECTNDC. This behavior is overridable so that applications can implement their own thumbnail drawing routines using an interface similar to CView printing.
SECTNWinApp
SECTNWinApp automatically creates an SECTNFileDialog when the user selects File|Open.
Using the Thumbnail Classes
To enable thumbnails in your application:
1. Replace your application object’s base class with SECTNWinApp.
2. Change your CView-derived class to derive from SECTNView. Add any custom thumbnail code to this class.
3. Change your CDocument derivative to derive from SECTNDocument. Be sure to call SECTNDocument::Serialize() first in your ::Serialize() method.
By default SECTNView generates a thumbnail that is the size of your entire view. SECTNView cannot infer how you want your view’s thumbnail to appear, so you need to write special thumbnail-generating code.
To generate custom thumbnails:
1. Derive a class from SECTNView and override the OnDraw() method.
2. In the OnDraw() override, you can determine if a thumbnail is being drawn by calling IsThumbNailing(). If the view is a thumbnail, draw the view’s thumbnail on the specified DC.
Thumbnail Sample
The Objective Toolkit thumbnl sample (Samples\Toolkit\MFC\UIExt\thumbnl) demonstrates the MFC scribble tutorial application with thumbnail support. This sample does not ship with the product. For information on how to obtain this sample, see “Location of Sample Code” in the Getting Started part.