开发者

How to add command to right-click menu of certain extension programmatically?

开发者 https://www.devze.com 2023-01-07 14:20 出处:网络
I have created 2 exe files:open.exe and edit.exe. and a new extension: say .newext. Now I want to open by double click on .newext file with open exe.

I have created 2 exe files: open.exe and edit.exe. and a new extension: say .newext.

Now I want to

  1. open by double click on .newext file with open exe.
  2. get a menu with right click on .newext file where in bold it is written "Open" and under that it is written 开发者_如何学运维"Edit". And by clicking "Edit" the edit.exe opens the .newext file.
  3. do this programmatically so that it could work on as much platforms as it is possible (at least on Xp, Vista, and Win7).

How I can achieve this?


You must edit the classes tree in the registry (using the registry functions from AdvApi32.dll). The following is not tested and off my head:

  • The base key is HKEY_LOCAL_MACHINE\Software\Classes for system-wide settings and HKEY_CURRENT_USER\Software\Classes for user-specific settings
  • In this base key, create a subkey with name .newext and default value X, where X is the class name (an arbitrary string that uniquely identifies the file type)
  • In the base key, create a subkey with name X and default value Y, where Y is the user-visible description of the file type
  • In the key X, create a subkey named shell with default value open
  • In the shell key, create a subkey named open with default value &Open
  • In the open key, create a subkey named command with default value "C:\path\to\open.exe" "%1"
  • In the shell key, create a subkey named edit with default value &Edit
  • In the edit key, create a subkey named command with default value "C:\path\to\edit.exe" "%1"
0

精彩评论

暂无评论...
验证码 换一张
取 消