Registering Program Manager Icons


Associating a file type with your application causes the Program Manager to use your application's default icon for program items created from files with the specified type (see Figure 19.5).

FIG. 19.5

When you add a program item with the file type .OLE, it is displayed with the icon from OLESTORE.EXE.

To use an icon other than the one displayed by default for the application, specify a DefaultIcon key in the application's registration entry file. To do this, follow these steps:

  1. Add a class module to your application. Name the class module after the last portion of the programmatic ID for your application. For example, if your programmatic ID is OleStore.Application, set the Name property of the class module to Application.
  2. Compile the application into an .EXE file.
  3. Run the .EXE file. When the application runs, it registers a class ID in the Registry for the class module you created in step 2. The following entries are added for the OLESTORE application:

    
    REGEDIT
    HKEY_CLASSES_ROOT\olestore.application\CLSID = {A4C17767-BB44-101B-BADD-4C696E65044C}
    HKEY_CLASSES_ROOT\CLSID\{A4C17767-BB44-101B-BADD-4C696E65044C}\TypeLib
    @= {A4C17761-BB44-101B-BADD-4C696E65044C}
    HKEY_CLASSES_ROOT\CLSID\{A4C17767-BB44-101B-BADD-4C696E65044C}\InprocHandler = OLE2.DLL
    HKEY_CLASSES_ROOT\CLSID\{A4C17767-BB44-101B-BADD-4C696E65044C}\LocalServer @
    
    = c:\\vb5 se\\samples\\chapter 17\\olestore.exe HKEY_CLASSES_ROOT\CLSID\{A4C17767-BB44-101B-BADD-4C696E65044C}\ProgID = olestore.application
  4. Add a DefaultIcon key to the class ID key in the Registry. For example, the following key indicates that OLESTORE should use the second icon stored in the application OLESTORE.EXE:

    
    HKEY_CLASSES_ROOT\CLSID\{A4C17767-BB44-101B-BADD-4C696E65044C}\DefaultIcon 
    
    @= c:\\vb5 se\\samples\\chapter 17\\olestore.exe, 2

    To register this line, you can either add it to the .REG file for the application and merge the registration file again, or you can add the key directly using the Registration Info Editor.

You should only use Visual Basic or an OLE utility called GUIDGEN.EXE to create class IDs. GUIDGEN.EXE is included in the \Tools\Idgen directory of the VB CD. Class IDs are very large numbers that are unique among all the applications installed on your system. If two applications use the same class ID, OLE can't distinguish between the two applications, and errors occur.