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 / June 2006

Tip: Looking for answers? Try searching our database.

How to remove named command?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kehlar - 06 Jun 2006 19:12 GMT
I have a toolbar with 3 buttons, each button is created by
EnvDTE::Command::AddControl() after the command has been added to the visual
studio 2005 environment via AddNamedCommand().

The problem I have is that I don't want these commands to be accessible
anywhere else in the environment. So here are my questions:

1. is there any other way to create a toolbar button or menu button
associated with a command that's NOT publicised anywhere in the enviroment
(ie Tools/Customize...)? I've read something about an unnamed command in
another post but have not been able to find a way to create it.

2. If 1 is false, is there a way to programmatically remove these named
commands? I would do that in my addin's OnDisconnection().

Thanks!
Carlos J. Quintero [VB MVP] - 07 Jun 2006 09:28 GMT
Hi,

> 1. is there any other way to create a toolbar button or menu button
> associated with a command that's NOT publicised anywhere in the enviroment
> (ie Tools/Customize...)? I've read something about an unnamed command in
> another post but have not been able to find a way to create it.

AFAIK, at least using the extensibility model for add-ins, no. Maybe using
the VSIP / VS 2005 SDK you can create unnamed commands with GUID and ID.

Alternatively you can create buttons without a command using the old way:
objCommandBarButton = CommandBar.Controls.Add(...). You get an event handler
for the Click event, etc.

> 2. If 1 is false, is there a way to programmatically remove these named
> commands? I would do that in my addin's OnDisconnection().

You can use EnvDTE.Command.Delete

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

kehlar - 07 Jun 2006 18:05 GMT
Thanks. I'll try the first method.

> Hi,
>
[quoted text clipped - 14 lines]
>
> You can use EnvDTE.Command.Delete
kehlar - 16 Jun 2006 01:45 GMT
> > 1. is there any other way to create a toolbar button or menu button
> > associated with a command that's NOT publicised anywhere in the enviroment
[quoted text clipped - 7 lines]
> objCommandBarButton = CommandBar.Controls.Add(...). You get an event handler
> for the Click event, etc.

Could you elaborate more on how this is accomplished? I managed to create
the buttons using CommandBar.Controls.Add(...). Unfortunately if I try to
pass anything but the value '1' for the id (the second parameter) it fails to
add. I don't see any type of event handling in CommandBarButton, the only
method that looks remotelylike one is OnAction() which takes a string and
doesn't seem to work unless it's in Visual Basic. How do I hook the OnClick
event for the button?

Thanks!
Carlos J. Quintero [VB MVP] - 16 Jun 2006 10:30 GMT
Hi,

- About CommandBar.Controls.Add(...), most parameters are optional. Just
pass the control type (msoControlButton) in the first parameter.
- About the event handling, there are two ways:

1) Cast the returned CommandBarControl to CommandBarButton, which has a
Click Event.
2) Use DTE.Events.CommandBarEvents(objCommandBarControl), cast to
EnvDTE.CommandBarEvents if needed, and you get the Click event.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

> Could you elaborate more on how this is accomplished? I managed to create
> the buttons using CommandBar.Controls.Add(...). Unfortunately if I try to
[quoted text clipped - 7 lines]
>
> Thanks!
kehlar - 20 Jun 2006 21:29 GMT
Hi Carlos,

Thanks for the tip. It looks really simple to use, unfortunately I'm writing
this in C++ (not by choice!) and it isn't as simple from what I can tell. My
addin implements this interface:

IDispEventImpl<0, CConnect, &EnvDTE::DIID__dispCommandBarControlEvents,
                      &EnvDTE::LIBID_EnvDTE, 8, 0>

which I typedef to be CommandBarEvents. I managed to get the EnvDTE::Event::
CommandBarEvents object for each of the toolbar buttons by calling
EnvDTE::Events::get_CommandBarEvents(), but when I try to call
DispEventAdvise() on each of them, it doesnt work. It seems that
DispEventAdvise() is only allowed to be called once in my addin, and calling
it once per button just crashes the system.

  CComPtr<CommandBarControl> pCtrl;
 <Add the toolbar button and store it in pCtrl>
  CComPtr<EnvDTE::Events> pEvents;
  IDispatch* pDispHandler;
  IfFailGo(m_pDTE->get_Events(&pEvents));
  IfFailGo(pEvents->get_CommandBarEvents(pCtrl, &pDispHandler));
  CommandBarEvents::DispEventAdvise((IUnknown*)pDispHandler);

I tried to find examples of how this is done but have had no luck so far. I
would appreciate any help there.

> Hi,
>
[quoted text clipped - 18 lines]
> >
> > Thanks!
kehlar - 21 Jun 2006 00:33 GMT
I found a work around for this problem, posting it for others who run into
the same issue.

IDispEventImpl::DispEventAdvise purposedly permits only one connection
through the use of a cookie. In order to listen to events of multiple buttons
you would need to bypass this function. Use AtlAdvise() instead and managed
the list of cookies in your own class (one cookie per button). In the OnClick
event you would need to distinguish the buttons by a name or id, which you
determined when you created the button (e.g. CommandBarButton::caption or
CommandBarButton::tag).

> Hi Carlos,
>
[quoted text clipped - 45 lines]
> > >
> > > Thanks!

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.