Document directory
- 1 shell item
- 2 shellex item
You can use the shell or shellex entry in the Registry to add a right-click menu.
1 shell item
Each computer I used will be added:
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT/Folder/shell/command prompt/command]@="cmd.exe"
Set the Registry "hkey_classes_root/folder/Shell/Command Prompt/Commander value to cmd.exe ". In this way, you can quickly enter the specified directory from the command line.
Hkey_classes_root has many keys that indicate the file type. Folder indicates a folder, and * indicates all files. Add the "shell/prompt string/command" item under the file type and set the value to the corresponding command line. In this way, when you right-click the corresponding file type in the resource manager, the content of a menu item in the menu will be "prompt string". If you select this menu item, the command set in the Command item will be executed. Let's look at another example:
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT/dllfile/shell/Register Component/command]@="regsvr32 /"%L/""[HKEY_CLASSES_ROOT/dllfile/shell/Unregister Component/command]@="regsvr32 /u /"%L/""[HKEY_CLASSES_ROOT/ocxfile/shell/Register Component/command]@="regsvr32 /"%L/""[HKEY_CLASSES_ROOT/ocxfile/shell/Unregister Component/command]@="regsvr32 /u /"%L/""[HKEY_CLASSES_ROOT/exefile/shell/Register Component/command]@="/"%L/" /regserver"[HKEY_CLASSES_ROOT/exefile/shell/Unregister Component/command]@="/"%L/" /unregserver"
This example adds the "register component" and "unregister component" commands to the types of dllfile, ocxfile, and exefile. In this way, you can register or Uninstall a component by right-clicking the menu. Under hkey_classes_root, you can see that the default value of .dll).ocxcmd.exe points to dllfile, ocxfile, and exefile.
Shell items are suitable for simple commands. If you want to right-click a menu to implement complex functions, you need to use the Windows Shell extended programming interface, that is, using the shellex item.
2 shellex item 2.1: COM component for Shell Extension
The shortcut menu of ultraedit is easy to use. So how is it implemented? You can see in the registry:
[HKEY_CLASSES_ROOT/*/shellex/ContextMenuHandlers/UltraEdit-32]@="{b5eedee0-c06e-11cf-8c56-444553540000}"
'{B5eedee0-c06e-11cf-8c56-444553540000}' is the uuid of a COM component. Under "hkey_classes_root/CLSID", you can find
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT/CLSID/{b5eedee0-c06e-11cf-8c56-444553540000}]@="UltraEdit"[HKEY_CLASSES_ROOT/CLSID/{b5eedee0-c06e-11cf-8c56-444553540000}/InProcServer32]@="C://Program Files//IDM Computer Solutions//UltraEdit-32//ue32ctmn.dll""ThreadingModel"="Apartment"
Ue32ctmn. dll is the COM component provided by ultraedit that implements the shell Extension function. If this COM component implements the icontextmenu interface, you can add a right-click menu. The icon text of a menu item is specified in the querycontextmenu function of the icontextmenu interface. After you select a menu item, Windows will call the invokecommand function of the icontextmenu interface. In this function, we implement the corresponding menu function.
We usually use ATL to implement COM components. Because VC provides a complete wizard, It is not complicated to use ATL to implement a COM component. On the Internet, you can find a CHM called "Full guide to Windows Shell extension programming", which contains detailed instructions for implementing shell extension programming. This is a translation article, and CHM also includes the original text (because the reprint requires the translator's consent, I will not provide the download ). The sample code can be downloaded from the original website.One copy. Using the alt wizard and following the sample code, we can easily build our own project. Then, you can customize the display and functions of menu items in the querycontextmenu and invokecommand functions. You can take the full guide to Windows Shell extended programming as a game strategy, find the part you are interested in, and just follow it.
2.2 add and remove menus
In addition to registering components, add a "shellex/contextmenuhandlers/descriptive name" under the corresponding file type and set the value to the uuid of the component. UUID is automatically generated when an ATL Project is created. The registration component is also completed by adding some items in the registry. When you remove a menu, you only need to delete the corresponding items in the registry.
Note that although the descriptive name under "shellex/contextmenuhandlers" is useless, users should be able to see which program the extension is added. For example, "beyond compare 2" has a strange name, so I deleted it. Later, I found that the right-click menu of BC2 was missing. I found the uuid of the DLL file of BC2 in CLSID, and added a "BC2" item in "*/shellex/contextmenuhandlers, set the default value to UUID.
For details about the component-related registry project, see the RGS file automatically generated when the ATL Project is created, as well as the dllregisterserver and dllunregisterserver functions.
Taking cnbook as an example, you need to add the following registry items to the right-click menu:
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT/*/shellex/ContextMenuHandlers/cnbook]@="{5BB33E44-519C-42A8-8ABF-81478C57A503}"[HKEY_CLASSES_ROOT/CLSID/{5BB33E44-519C-42A8-8ABF-81478C57A503}]@="Shellapi.OpenExt"[HKEY_CLASSES_ROOT/CLSID/{5BB33E44-519C-42A8-8ABF-81478C57A503}/InProcServer32]@="D://projects//cnbook//cnbook//shellapi.dll""ThreadingModel"="Apartment"[HKEY_CLASSES_ROOT/CLSID/{5BB33E44-519C-42A8-8ABF-81478C57A503}/ProgID]@="Shellapi.OpenExt"[HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Shell Extensions/Approved]"{5BB33E44-519C-42A8-8ABF-81478C57A503}"="Shellapi.OpenExt"
You only need to delete these items to remove the menu. Progid is the name of the ATL object entered when the ATL object is inserted. The component path can be determined in the application directory.