Author: |
Carlos J. Quintero (Microsoft MVP) |
Applies to: |
Microsoft Visual Studio .NET 2002 |
Date: |
May 2009 |
|
Microsoft Visual Studio .NET 2003 |
Updated: |
March 2013 |
|
Microsoft Visual Studio 2005 |
|
|
|
Microsoft Visual Studio 2008 |
|
|
|
Microsoft Visual Studio 2010 |
|
|
|
Microsoft Visual Studio 2012 |
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.Window.ObjectKind property returns a Guid that identifies the
kind:
- For a toolwindow 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.
- For a document window 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
- 10.0 for Visual Studio 2010
- 11.0 for Visual Studio 2012
- The EnvDTE.Window.Kind property returns "Tool" for toolwindows and "Document"
for document windows, so it is quite useless.
- 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.Caption returns the caption, but you should avoid to use this
property to identify a toolwindow because it is localized.
Related articles
Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)
|