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