Chapter Twelve: File Viewers

Let's say that you have created some Microsoft Word documents named STUFF1.DOC, STUFF2.DOC, and STUFF3.DOC. Now let's say that you want to give those files to a reviewer who doesn't use Word. (Heresy, I know, but there's always one in the crowd.) You can of course resave the documents as text files that can be read with any text editor. Or, if the reviewer happens to be running the Microsoft Windows 95 operating system, he or she can use a file viewer to check out the files.

A file viewer, one of the new features of Windows 95, allows a user to quickly see the contents of a file without having to run the full application that created the file—in fact, without even requiring the presence of that application. The file viewer not only displays a file's contents but also provides a user interface that can include items such as a menu, a toolbar, and a status bar.

To use a file viewer, you first right-click a file to display its context menu, which will look something like the menu shown in Figure 12-1 on the next page. Then simply choose the Quick View option from the context menu to display the file contents in a file viewer. (Alternatively, you can select the file and choose Quick View from the File menu in Windows Explorer.)

Before you go off and try this on your computer, however, be aware that the Quick View option will not appear on a file's context menu unless a file viewer is registered for that particular type of file (DOC, TXT, AVI, and so on). The option is displayed only if you have a file viewer installed and if that file viewer has registered itself properly in the Registry. When you right-click a file, the system checks the Registry to find a viewer for that file based on the file's extension and class. If no file viewer is registered for that file type, the Quick View option doesn't appear on the context menu.

Figure 12-1.

A context menu containing the Quick View option.

If you install the sample I wrote for this chapter, MFCVIEW, you will have a rudimentary file viewer for text files, shown in Figure 12-2. You need to copy the dynamic-link library to your \WINDOWS\SYSTEM\VIEWERS folder and then run the MFCVIEW.REG file. The DLL is registered to reside in this path; if you want to place the DLL somewhere else, change the REG file to reflect the new location. (If you rebuild the project, the DLL file will automatically be placed in \WINDOWS\SYSTEM\VIEWERS. You can change this location by going to the Project menu, choosing Settings, clicking the Link tab, and changing the Output File Menu item. Then click the Debug tab and edit the Executable For Debug Session and the Working Directory items. You must alter these three items for both Win32 Debug and Win32 Release. Note that you must still change and run the REG file.)

Figure 12-2.

Nancy's Viewer (a rudimentary file viewer).