Special CWinApp Services

OverviewHow Do ITutorial

Besides running the message loop and giving you an opportunity to initialize the application and clean up after it, provides several other services.

Shell Registration

By default, AppWizard makes it possible for the user to open data files that your application has created by double-clicking them in the Windows Explorer or File Manager. If your application is an MDI application and you specify an extension for the files your application creates, AppWizard adds calls to the and member functions of to the InitInstance override that it writes for you.

RegisterShellFileTypes registers your application's document types with Windows Explorer or File Manager. The function adds entries to the registration database that Windows maintains. The entries register each document type, associate a file extension with the file type, specify a command line to open the application, and specify a dynamic data exchange (DDE) command to open a document of that type.

EnableShellOpen completes the process by allowing your application to receive DDE commands from Windows Explorer or File Manager to open the file chosen by the user.

This automatic registration support in CWinApp eliminates the need to ship an .REG file with your application or to do special installation work.

File Manager Drag and Drop

Windows versions 3.1 and later allow the user to drag file names from the file view window in the File Manager (or Windows Explorer in Windows 95 and later and in Windows NT 4.0 and later) and drop them into a window in your application. You might, for example, allow the user to drag one or more filenames into an MDI application's main window, where the application could retrieve the file names and open MDI child windows for those files.

To enable file drag and drop in your application, AppWizard writes a call to the member function for your main frame window in your InitInstance. You can remove that call if you do not want to implement the drag-and-drop feature.

Note   You can also implement more general drag-and-drop capabilities — dragging data between or within documents — using OLE. For information, see the article Drag and Drop (OLE).

Keeping Track of the Most Recently Used Documents

As the user opens and closes files, the application object keeps track of the four most recently used files. The names of these files are added to the File menu and updated when they change. The framework stores these file names in either the registry or in the .INI file, with the same name as your project and reads them from the file when your application starts up. The InitInstance override that AppWizard creates for you includes a call to the member function , which loads information from the registry or .INI file, including the most recently used file names.

These entries are stored as follows:

  • In Windows NT, the value is stored to a registry key.

  • In Windows 3.x, the value is stored in the WIN.INI file.

  • In Windows 95, the value is stored in a cached version of WIN.INI.