Basic Steps in Creating a File Viewer

You have two options when you decide to write your own file viewer: you can take the really hard way and use C, or you can use MFC version 3.1 or later and let MFC do a lot of the grunt work for you. Since one of the rules I live by is “Don't do anything that you can get someone else to do for you,” I chose the MFC method. If you want to do all the work yourself, you aren't out of luck: the FILEVIEW sample in the Win32 SDK demonstrates exactly what you have to do to reinvent that wheel.

When I wrote the MFCVIEW sample, I followed the steps outlined in a technical article by Nigel Thompson, “MFC/COM Objects 1: Creating a Simple Object”msdn_house1(available on the Microsoft Developer Network Development Library CD), and the information in “Technical Note 38: MFC/OLE IUnknown Implementation” (one of the MFC technical notes found in the Visual C++ documentation). So if you think the steps look familiar and you've read Nigel's article recently, you'll know why.

Here is what I did to create Nancy's Viewer:

  1. Create the project.
  2. Generate GUIDs.
  3. Create the object class.
  4. Implement the basic object.
  5. Implement the IUnknown interface.
  6. Implement the IFileViewer interface.
  7. Implement the IPersistFile interface.
  8. Let MFC initialize the class factories for you.
  9. Create the class to show the file contents.
  10. Build, register, and run the file viewer.