HI all,
I am creating small VS.NET add-in and have 2 problems:
1. I am extending context menus in the different windows. I am able
succesfully add commands to context menus of code editor ("Code Window"),
help window ("DefaultContext") and selection context in help window
("SelectionContext")
But I do not know, how to extend the context menus in WebPage - HTMLView and
when editing XML file. I have used Command Browser sample tool but it seems
the two context menus name is "Context" and there are more such menus named
"Context".
2. I would like to access the selection text of the currently active window.
I am able access the selection text in the "Code Window" using this code:
TextSelection selectedText = (TextSelection)
applicationDTEObject.ActiveWindow.Document.Selection;
but when I use this code in the "DefaultContext" or "SelectionContext", the
ActiveWindow property is null and I am not able to get the selected text in
the help window.
I will need to access the selected text from the WebPage -> HTML View and
XML file editor too, if I will solve the problem 1.
Thanks for your answers.
Ondrej
Ondrej Maler - 26 Nov 2004 09:21 GMT
To be correct:
ActiveWindow is not null, but ActiveWindow.Document is null and
ActiveWindow.Selection is null too.
Ondrej
> TextSelection selectedText = (TextSelection)
> applicationDTEObject.ActiveWindow.Document.Selection;
>
> but when I use this code in the "DefaultContext" or "SelectionContext", the
> ActiveWindow property is null and I am not able to get the selected text in
> the help window.
----------------------------------------------------------------------------
----------------
> HI all,
>
[quoted text clipped - 26 lines]
>
> Ondrej
Carlos J. Quintero [MVP] - 26 Nov 2004 09:57 GMT
1) See this article of mine:
HOWTO: Guessing the name of a command bar to add a custom menu entry in
Visual Studio .NET add-ins.
http://support.microsoft.com/default.aspx?scid=kb;en-us;555154
2) I am not sure if add-ins can get the selection of HTML windows using the
extensibility model, because I think that these use internally MSHTML. Try
this little add-in:
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
Dim objWindow As Window
Dim objObject As Object
Dim objHTMLWindow As HTMLWindow
Try
applicationObject = CType(application, EnvDTE.DTE)
addInInstance = CType(addInInst, EnvDTE.AddIn)
objHTMLWindow = CType(applicationObject.ActiveWindow.Object, HTMLWindow)
objObject = objHTMLWindow.CurrentTabObject
System.Windows.Forms.MessageBox.show(Microsoft.VisualBasic.Information.TypeName(objObject)
Catch objException As Exception
System.Windows.Forms.MessageBox.Show(objException.ToString)
End Try
End Sub
For HTML windows in Design tab, you get that the type name of the editor is
"CoClassMshtml". You can get more information about MSHTML at:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/editing/msht
mleditor.asp

Signature
Carlos J. Quintero
The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
> HI all,
>
[quoted text clipped - 32 lines]
>
> Ondrej