Associating a File Type with Your
Application
The Registry contains FileType keys that identify specific file extensions as
belonging to specific applications. This key allows the Windows shell functions to start
an application for loading the file when the user double-clicks the file name in the
Explorer or a shortcut for the file on the Windows desktop.
To associate a file type with your application, follow these steps:
- Create a registration file for your application. The following file registers
OLESTORE.EXE and creates associations for loading and printing the file.
Listing
19.23 - Registering the OLE File Type
; Comments: OLESTORE.REG
REGEDIT
; Register OLESTORE.EXE.
HKEY_CLASSES_ROOT\olestore.application = OLE Samples Storage View Utility
; Provide open and edit command lines for the Explorer
HKEY_CLASSES_ROOT\olestore.application\shell\open\command
@= c:\\vb5 se\\samples\chapter 17\\olestore.exe %1
HKEY_CLASSES_ROOT\olestore.application \shell\print\command
@= c:\\vb5 se\\samples\\chapter 17\\olestore.exe %1
; Associate .OLE file extension with the progID.
HKEY_CLASSES_ROOT\.ole = olestore.application
; Enables drag-drop to program icon (starts application)
[HKEY_CLASSES_ROOT\olestore.application\shellex\drophandler]
@="{99920810-0000-0000-C000-000000000046}"
: Adds OLEStore to File/New context menu from desktop
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.ole]
@="olestore.application"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.ole\ShellNew]
"Command"="c:\\vb5 se\\samples\\olestore.exe /n\""
@="OLE Storage File"
- Merge the registration file. The following command line merges the file OLESTORE.REG
with the Registry. The /s switch merges the changes silently - no confirmation dialog box
is shown.
regedit /s olestore.reg
- After merging the file, you can view the changes using the Registration Info Editor (see
Figure 19.4).
FIG. 19.4
The Registry entries for OLESTORE.REG.