开发者

How to set a icon for this right click menu?

I can add a new item for the folders right click menu using registry:

HKEY_CLASSES_ROOT\folder\shell\Your item name

But i don't know how to set a icon for created item like this :

开发者_开发技巧

How to set a icon for this right click menu?

May somebody help me?


To create a custom context menu with an icon when clicking on a folder follow these steps:

  1. Under HKEY_CLASSES_ROOT\folder\shell\ create a new key: "MyContextMenu"
  2. Under HKEY_CLASSES_ROOT\folder\shell\MyContextMenu edit the (Default) key to specify the text to show in the context menu: MyMenu
  3. To execute a command when the menu is chosen add a new key name "Command" and set the commmand to execute in it's (Default) value. For instance: cmd.exe
  4. Now to set the icon you add a new string value name Icon and set it's value to the *.ico you want to show or you can reference an ico that is embedded in a dll using [name of the dll],[icon number] A lot of the default windows icons are in imageres.dll. So for this example set the value to: c:\windows\system32\imageres.dll,10

There is a nice tool called iconviewer that you can use to examine icons in dlls. After you install it you can right click a dll, open it's properties and an extra tab with it's icons will be added to the propery pages


You should to add iconpath in this key for showing when the user clicked right button. Try to write key OpenWithProgIds, and then create value with name (path) of your application. Example for recycle:

TRegistry *key=new TRegistry(KEY_ALL_ACCESS);
    key->RootKey=HKEY_LOCAL_MACHINE;
    key->OpenKey("Software\\Classes\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\shell", false);
    key->OpenKey("Prog_name", true);
    key->WriteString("Icon", ExtractFileDir(Application->ExeName)+"\\icon_prog.ico");
    key->OpenKey("command", true);
    key->WriteString("", ExtractFileDir(Application->ExeName)+"\\Program.exe");
    key->CloseKey();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜