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 / February 2005

Tip: Looking for answers? Try searching our database.

adding a button in vsnet from an application that is not an addin

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
palaga - 14 Feb 2005 15:13 GMT
Hi
From within my application, I get a Dte object for a running msdev instance,
using :

Solution dte;
dte =
(Solution)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStud
io.Solution.7.1");

is there a way I can add, in this specific instance, a new menu (or tool bar
or command entry), so that when the user selects my specific entry, it calls
a callback in my application ? (What i've seen so far always need an 'addin
instance' object, but I am not an addin...)

If this is not possible, what solution do I have to make a button in vsnet
execute a specific action in my non-addin application ?

thanks
Carlos J. Quintero [.NET MVP] - 15 Feb 2005 09:59 GMT
Yes, it's possible. You need to add references to EnvDTE and
Microsoft.Office.Core. Below is the code (VB.NET).

Carlos J. Quintero

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

Private m_objDTE As EnvDTE.DTE
Private WithEvents m_objCommandBarButton As
Microsoft.Office.Core.CommandBarButton

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

 Dim objType As Type
 Dim objCommandBar As Microsoft.Office.Core.CommandBar
 Dim objCommandBarControl As Microsoft.Office.Core.CommandBarControl

 Try

  objType = System.Type.GetTypeFromProgID("VisualStudio.DTE")
  m_objDTE = DirectCast(System.Activator.CreateInstance(objType),
EnvDTE.DTE)
  m_objDTE.MainWindow.Visible = True
  objCommandBar = m_objDTE.CommandBars.Item("Tools")
  objCommandBarControl =
objCommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton)
  m_objCommandBarButton = DirectCast(objCommandBarControl,
Microsoft.Office.Core.CommandBarButton)

  m_objCommandBarButton.Caption = "Test"

 Catch ex As Exception
  MessageBox.Show(ex.ToString)
 End Try

End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed

 Try

  If Not (m_objCommandBarButton Is Nothing) Then
   m_objCommandBarButton.Delete()
  End If

  If Not (m_objDTE Is Nothing) Then
   m_objDTE.Quit()
  End If

 Catch ex As Exception
  MessageBox.Show(ex.ToString)
 End Try

End Sub

Private Sub m_objCommandBarButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles m_objCommandBarButton.Click

 MessageBox.Show("You clicked me!")

End Sub

> Hi
> From within my application, I get a Dte object for a running msdev
[quoted text clipped - 18 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.