Click here to Skip to main content
Click here to Skip to main content

Changing the Visual Studio .NET Add-in Default Tool Menu Item Icon

, 11 Jul 2002
Rate this:
Please Sign up or sign in to vote.
This article discusses how to change the icon that is placed on the tools menu by the Visual Studio .NET Add-in Wizard
<!-- Download Links --> <!-- Article image -->

Sample Image - vsnet_addin_icon_change.gif


Note:
Difference in application GUI is just that I took the first screenshot at work, the second at home.

<!-- Add the rest of your HTML here -->

Let the Wizard Guide You

This article came about because I wanted to make an Add-In for Visual Studio .NET. The Wizard makes this relatively painless. You can find the wizard under File/New/Project, then under Other Projects/Extensibility Projects/Visual Studio .NET Add-in. Make sure to check the box that says "Yes, create a 'Tools' menu item."

Once the wizard is finished, you can then build the add-in and then run the setup MSI that is included in the new solution. Then when you press F5 to bring up a debugging session Visual Studio .NET will be launched and in this new instance, you should be able to see your new add-in under the tools menu. It should look like the first image at the top of this page (unless you renamed your project, it will be your project's name in that case).

Creating the Satellite DLL

In order for the IDE to find your new icon, you must embed the bitmap in an external generic Win32 C DLL. You cannot insert the bitmap into the assembly containing the Add-in. Why it was done this way, I cannot tell you.

To build this Win32 satellite DLL, you must add a new project to the add-in solution. You can do this from File/Add Project/New Project, then under Visual C++/Win32 Project. In the window that pops up, click Application Settings and then click DLL then Finish.

Now find the bitmap you wish to use as your icon and add it to the DLL project. There are certain restrictions on the bitmap. These are:

  • It must be 16 pixels by 16 pixels
  • It must be a 16 color bitmap
  • The color to use for transparency is Red = 0, Green = 254, Blue = 0 (RGB=00FE00h)

Note: The bright green that is on the palette by default is not the correct green.

Now add a resource file to the project. Then in resource view, right-click on the newly added .rc file and then click Add Resource then Import to insert the bitmap into the resource file. In the properties panel, change the ID of the bitmap from "IDB_BITMAP1" to "1" (no quotes). Build the solution.

You now have a satellite DLL with the bitmap embedded.

Associating the Satellite DLL with the Add-in

Now that you have a satellite DLL, you need to tell Visual Studio .NET that it is there. This is done via the registry. Two values need to be added to HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE Software\Microsoft\VisualStudio\7.0\Addins\<AddInName> (make sure to change the <AddInName> to the actual name of your add-in:

Note: The hive to add these values to depends on if you chose the option to have it installed so that everyone can use it.

  • SatelliteDLLName = NameOfTheDLL.DLL
  • SatelliteDLLPath = C:\InstallPathOfTheAddIn

Both of these can be done via the installer that is in the solution. Just right-click on the deployment solution and go to View/Registry. To get the installation folder on installation, use [TARGETDIR] as the value set in the SatelliteDLLPath variable.

The next thing to do is to place the satellite DLL in a special folder underneath the installation folder. This folder is the <SatelliteDLLPath>\1033. The 1033 is just the ID number of the English_Language/Sub-language_English_US. If your system is not a US system you will need to place the satellite DLL in your localized code number directory.

You can set this directory by right-clicking on the deployment project and going to View\File System. Then add a directory under Application Folder, specifying 1033 (or you preferred language directory) as the folder name. Then you need to add the primary output of the satellite DLL project to this directory. This can be done via a right-click on the deployment project and then clicking Add/Project Output, then moving the primary output of the DLL to the language directory.

A Code Change

Now that the association is done, you need to open the file Connect.cs in the main add-in project and find the OnConnection method. In this method locate the try/catch block at the bottom (it should look like this):

try
{
    Command command = commands.AddNamedCommand(addInInstance, "MyAddin1", "MyAddin1",
        "Executes the command for MyAddin1", true, 59, ref contextGUIDS,
        (int)vsCommandStatus.vsCommandStatusSupported+(int)
        vsCommandStatus.vsCommandStatusEnabled);
    
    CommandBar commandBar = (CommandBar)commandBars["Tools"];
    CommandBarControl commandBarControl = command.AddControl(commandBar, 1);
}
catch(System.Exception /*e*/)
{
}

The important line is:

Command command = commands.AddNamedCommand(addInInstance, "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled);

Change the true to false and 59 to 1. This tells Visual Studio .NET that the bitmap is not a built in icon, instead look at the add-in's satellite DLL and load the bitmap with the ID '1'.

Now if you build the project and then reinstall the add-in your icon should have changed.

Some Gotchas

  • If the add-in does not display in the IDE, run the file ReCreateCommands.reg in the main add-in directory and restart the IDE.
  • Also rerunning the installation process seems to fix the same problem (sometimes).

References

I would like to thank Carlos for his newsgroup posts, where I found a lot of the answers for my Add-in questions.

Also, I used the MSDN Library for some info; though the MSDN Library seems lacking in the VS .NET Add-in documentation.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Nathan Blomquist
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
QuestionVC++ 6.0 Toolbar Application to be deployed in DOTNET Pinmemberthatharo20-Nov-05 20:02 
QuestionHow to execute MyAddin menu PinsussAnonymous14-Jul-05 0:50 
AnswerRe: How to execute MyAddin menu PinmemberNathan Blomquist14-Jul-05 4:18 
GeneralRe: How to execute MyAddin menu Pinmemberyu-yu14-Jul-05 14:38 
GeneralDarn useful! Pinmembersoup20-Jun-04 23:08 
QuestionHow to change BuildTool of file in Add in Pinmember""21-Feb-03 8:33 
GeneralRun devenv /setup PinmemberDouglas Earl6-Dec-02 11:41 
GeneralRegistering PinsussJulien Grosclaude11-Nov-02 8:59 
GeneralRe: Registering PinmemberNathan Blomquist12-Nov-02 7:10 
GeneralThe registry way... PinmemberHeath Stewart2-Oct-02 17:53 
GeneralRe: The registry way... Pinmemberdang!2-Sep-03 15:21 
GeneralRe: The registry way... PineditorHeath Stewart2-Sep-03 16:56 
GeneralRe: The registry way... Pinmemberdang!2-Sep-03 17:02 
GeneralRe: The registry way... PineditorHeath Stewart2-Sep-03 17:05 
GeneralRe: The registry way... Pinmemberokigan11-Jan-04 11:36 
GeneralRe: The registry way... PinmemberNathan Blomquist12-Jan-04 2:58 
GeneralAnd... PinsussAnonymous15-Jul-02 3:46 
GeneralRe: And... PinmemberJamie Nordmeyer16-Jul-02 5:40 
GeneralRe: And... PinmemberAlexandru Stanciu4-Nov-05 0:14 
GeneralRe: And... PinmemberShof8-Apr-07 22:43 
Generalsame on MSDN PinmemberSteveKing14-Jul-02 23:08 
GeneralVery informative - Well done! PinmemberAndy Metcalfe13-Jul-02 10:57 
GeneralRe: Very informative - Well done! PinmemberNathan Blomquist13-Jul-02 12:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 12 Jul 2002
Article Copyright 2002 by Nathan Blomquist
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid