Visual Studio Hacks [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Visual Studio Hacks [Electronic resources] - نسخه متنی

Andrew Lockhart

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







Hack 91. Change the Icon for Your Add-in

Learn how to replace that not-so-lovely smiley
face of an icon for your add-in.

By default, when you create a new
Visual Studio add-in, you are given a goofy smiley face icon as the
icon for your add-in. If you plan on sending your add-in out to
anyone, I highly recommend creating your own icon or setting it to a
more appropriate built-in icon. Customizing the icon used with your
add-in is not as easy as it should be. In this hack, you will learn
the steps needed to create this custom icon, and then ensure that it
is installed properly with your add-in.


12.7.1. Creating the Icon


The first step is to create a satellite
assembly and embed an icon in that
assembly. Yes, you actually have to create a new assembly; you
can't just embed the resource in your
add-in's assembly!

Add a new Class Library Project to your Add-in Solution (File
New Project).

Add a new bitmap to your project. Using the bitmap editor (just
double-click on your bitmap to open it), you can create a bitmap. The
size of the bitmap should be 16 by 16, and if you want to use
transparency, use Red: 0, Green: 254, Blue: 0. Figure 12-18 shows the bitmap editor.


Figure 12-18. Bitmap editor

Compile your Class Library Project and then click the Show All Files
button on the Solution Explorer.

Navigate to the obj Debug folder in the Solution Explorer
and then double-click on the .dll file.

Right-click on the root folder and select Add Resource as shown in
Figure 12-19.


Figure 12-19. Add Resource button

From the Add Resource dialog, select Icon and then click on Import as
shown in Figure 12-20.


Figure 12-20. Add Resource dialog


Navigate to your bitmap file and click OK.

Your icon will now be embedded in the satellite assembly. After
embedding the bitmap, note the ID of the bitmap since you will be
using that later.


12.7.2. Modify Command Code


The
default code to add a
command created by the Add-in Wizard is
shown here:

Command command = commands.AddNamedCommand(addInInstance, 
"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch",
true, 59, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported
+(int)vsCommandStatus.vsCommandStatusEnabled);

The Boolean value here represents whether the icon you are using is a
Microsoft icon or a custom icon. You will need to change this to
false and then replace the number 59 with the ID of your bitmap.
(This is usually 101, but you can check by double-clicking on your
assembly in Visual Studio and expanding the folder named Bitmap).
Here is the new line of code:

Command command = commands.AddNamedCommand(addInInstance, 
"TryCatchMatic", "TryCatchMatic", "Surround W/ Try..Catch",
false, 101, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported
+(int)vsCommandStatus.vsCommandStatusEnabled);

This command will now try to use the bitmap with the ID 101 in your
new assembly.

You could alternatively set the icon to another of the default icons.
You could do this by leaving the Boolean value set to true and then
specifying another number instead of 59. To view a list of all the
available icons, you can use a small utility available from
http://www.visualstudiohacks.com/iconspy.


12.7.3. Add to Installer


Finally,
you need to configure the installer
to include your new assembly and add a couple of new keys to the
registry to tell Visual Studio where your icon is.

To add assembly:


Right-click on the setup project and choose View File
System.

Create a directory called 1033 (or your local version, if you are not
using English) under the Application Folder.

Right-click on the 1033 folder and choose Add Assembly.

This will display the Add Assembly dialog from which you can select
your assembly. The final result is shown in Figure 12-21.



Figure 12-21. Setup projectFile System

Your satellite assembly will now be installed when your add-in is
installed.

To add registry keys:

Right-click on the setup project and
choose View Registry.

Navigate to HKEY_CURRENT_USER Software
Microsoft VisualStudio 7.1
AddIns
MacroName.

Add a new string value called SatelliteDllName and
enter the name of your .dll file as the value.

Add a second string value called SatelliteDllPath
and enter a value of [TARGETDIR]. Figure 12-22 shows the end result.


Figure 12-22. Setup projectregistry settings

Next, you will need to rebuild your setup project and then reinstall
your add-in. You may need to run devenv
/setup for your changes to take effect
[Hack #92] .

After reinstalling your add-in, you will now see your icon in the
Tools menu, as shown in Figure 12-23.


Figure 12-23. Add-in with new icon

Adding a custom icon for your add-in is not the easiest of
procedures, but it is definitely a must if you
plan on distributing your icon to other users.


/ 172