4.1 Static Context Menus

only for RuBoard - do not distribute or recompile

4.1 Static Context Menus

Static context menu items are listed under the application identifier key under a subkey called shell (as opposed to the shellex key). These entries remain constant for every instance of the file object and require no implementation code.

Figure 4.2 illustrates how to add an Open context menu item to the .rad file. The subkey of shell (in this case open ) is the verb value for the command. There are seven verbs, called canonical verbs , whose meaning is automatically recognized by the shell: open , find , explore , print , printto , openas , and properties . (The printto key is never shown in a context menu, but allows a file to be dragged to a printer object for printing.)

Figure 4.2. Registry entry for static "Open" context menu
figs/vshl.0402.gif

The default value of the verb key contains the text for the context menu; in the case of Figure 4.2, the open verb is described in the context menu as "Open." The verb key's subkey is the command key, whose default value contains the path of the file that will be used to carry out the command. The %1 portion of this string in Figure 4.2 denotes the file that was selected within the shell. Whatever file is selected will be passed to notepad.exe on the command line. Of course, this only works because notepad.exe accepts command-line arguments.

However, don't believe for a second that you are limited to these seven canonical verbs. You can actually add you own commands to the context menu and call them anything you want. For example, let's add Register and Unregister commands to the context menu for DLLs. This will provide us with a convenient way to register and unregister components .

To accomplish this, we need to locate the application identifier key for a DLL, which happens to be dllfile . Then, under the shell subkey, we add two other keys: Register and Unregister . Figure 4.3 shows how the relevant portion of the registry should appear in order to support these two static commands.

Figure 4.3. Static menu handlers to register and unregister DLLs
figs/vshl.0403.gif

As you can see from Figure 4.2, we must also add an additional subkey named command . The default value for this key will contain the command that we actually want to execute. The following script, DLLRegister.reg , will do everything for you:

 REGEDIT4 [HKEY_CLASSES_ROOT\dllfile\shell\Unregister\command] @="regsvr32.exe /u %1" [HKEY_CLASSES_ROOT\dllfile\shell\Register\command] @="regsvr32.exe %1" 
only for RuBoard - do not distribute or recompile


Visual Basic Shell Programming
Visual Basic Shell Programming
ISBN: B00007FY99
EAN: N/A
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net