Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
HOWTO: Getting information about Visual Studio windows from an add-in

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: May 2009   Microsoft Visual Studio .NET 2003
      Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
Introduction

Visual Studio provides three kinds of windows, all of them modeled as an EnvDTE.Window class:

  • The main IDE window, which can be retrieved through EnvDTE.DTE.MainWindow.
  • Document windows, which are always tabbed and belong to documents. You can get the open documents with the EnvDTE.DTE.Documents collection, and the active document with the EnvDTE.DTE.ActiveDocument property. Each document can have one or more windows opened belonging to it (a code window and a designer window, for example). You can get the windows of a document with the EnvDTE.Document.Windows collection, and the active window of a document with the EnvDTE.Document.ActiveWindow property. Given an EnvDTE.Window, you can get its document with the EnvDTE.Window.Document property. If the document is a text document, you can cast the EnvDTE.Document to EnvDTE.TextDocument to get new functionality available only for text documents.
  • Toolwindows, which can be tabbed, docked or floating. See HOWTO: Understanding toolwindow states in Visual Studio.

You can get the windows of the IDE (toolwindows or document windows) using the EnvDTE.DTE.Windows collection, and the active window (either toolwindow or document window) using the EnvDTE.DTE.ActiveWindow. Notice that EnvDTE.ActiveDocument.ActiveWindow may be different from EnvDTE.DTE.ActiveWindow (if a toolwindow is active, or if there is no active document).

More Information

Given an EnvDTE.Window, you can use several properties to get information about it:

  • The hidden EnvDTE.Window.Type property (in the Object Browser you need to check the "Show Hidden Types and Member" option in the dropdown button of the toolbar to show it) returns an enum of the hidden EnvDTE.vsWindowType type. However, you shouldn't use this property (it is hidden for a good reason): new Visual Studio versions or 3rd party packages can provide new window types that are not included in the EnvDTE.vsWindowType enum. For example, the Error List toolwindow type introduced by Visual Studio 2005 is not included. You should use this property only to check if the value of EnvDTE.Window.Type is vsWindowType.vsWindowTypeMainWindow (the IDE window) or vsWindowType.vsWindowTypeDocument (a document window). Otherwise it is a toolwindow and you can use the following property to identify which one.
  • The EnvDTE.Kind property returns also the type or kind of the window. But on the contrary to the previous property, this one is of the String type and contains a Guid that uniquely identifies the window. Being of String type, it can accommodate new window kinds of new Visual Studio versions or 3rd party packages. The automation model provides the following classes with constants that are the Guids of most window kinds:
    • EnvDTE.Constants.vsext_wk_XXX: do not use. Use the following ones instead.
    • EnvDTE.Constants.vsWindowKindXXX: vsWindowKindClassView, vsWindowKindLocals, etc.
    • EnvDTE80.WindowKinds.vsWindowKindXXX: new toolwindows introduced by Visual Studio 2005.
  • The EnvDTE.Window.Object property returns the underlying object hosted in the window (see HOWTO: Know the actual type behind a System.__ComObject type returned by an .Object property):
  • The EnvDTE.Window.ObjectKind property returns the Guid that identifies the underlying hosted object. For example, for document windows you can get the editor type used in that window. You can get the list of editor Guids registered for Visual Studio using the following registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\m.n\Editors

    where m.n is:
    • 7.0 for Visual Studio .NET 2002
    • 7.1 for Visual Studio .NET 2003
    • 8.0 for Visual Studio 2005
    • 9.0 for Visual Studio 2008

Related articles


Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top