Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / September 2006

Tip: Looking for answers? Try searching our database.

Adding a new item to a built-in context menu

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Chambers - 22 Sep 2006 19:37 GMT
Hi there,

I want to add a new item to the Solution Explorer context menu immediately
before the "Properties" item. I think I have most of the details now worked
out but how do I locate the "Properties" index in the menu given that my
Add-In will be running in different languages. I assume the name of the
command bars themselves don't change between languages (can someone confirm
this) but how do I locate "Properties" itself (presumably each item has a
unique ID but where is this). Thanks very much.
Dustin Campbell - 22 Sep 2006 20:18 GMT
> I want to add a new item to the Solution Explorer context menu
> immediately before the "Properties" item. I think I have most of the
[quoted text clipped - 3 lines]
> languages (can someone confirm this) but how do I locate "Properties"
> itself (presumably each item has a unique ID but where is this).

CommandBar.Name does not change in other languages but CommandBar.NameLocal
does. However, there's no guarantee that CommandBar.Name is unique between
other CommandBars. In fact, several CommandBars have the same name. Fortunately,
in this case ("Solution" & "Project"), you should be ok.

There really isn't a unique ID for CommandBarControls. CommandBarControl.Id
doesn't seem to be the same between VS 2003/2005 and I'm pretty certain that
CommandBarControl.InstanceId is just a pointer to some internal structure.

The trick to determining the differenece between built-in Visual Studio CommandBarControls
from within an add-in is to use the DTE.Commands.CommandInfo() method and
pass your CommandBarControl into it. This will return the guid:id pair for
the command that this CommandBarControl is linked (a full list of these can
be found in the header files that ship with the Visual Studio SDK).

Armed with this knowledge, you can find the Properties CommandBarControl
using code like this:

public void OnConnection(object application, ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
 _applicationObject = (DTE2)application;
 _addInInstance = (AddIn)addInInst;

 CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
 CommandBar solutionBar = commandBars["Solution"];
 Commands commands = _applicationObject.Commands;
 foreach (CommandBarControl control in solutionBar.Controls)
 {
   string guid;
   int id;
   commands.CommandInfo(control, out guid, out id);

   if (id == 397 && String.Compare(guid, "{5EFC7975-14BC-11CF-9B2B-00AA00573819}",
true) == 0)
   {
     System.Diagnostics.Debug.WriteLine("Found it!");
     break;
   }
 }
}

This works ok -- if a bit flimsy. The preferred way to add menu items is
with a via Visual Studio package where you have better control.

Best Regards,
Dustin Campbell
Developer Express Inc.
Michael Chambers - 22 Sep 2006 20:35 GMT
Thanks very much for the info (appreciated). I'll take some time to digest
it and post back if I have any further questions. Thanks again.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.