We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

_DTE.ActiveWindow Property

Returns the currently active window, or the top-most window if no others are active.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Window ActiveWindow { get; }

Property Value

Type: EnvDTE.Window
A Window object. Returns Nothing if no windows are open.

ActiveWindow returns the environment's active window.

You can set the caption only on Tool windows. If you attempt to set the caption on other window types, such as Document windows, you get the error, "Unspecified error."

public void ActiveWindowExample(DTE2 dte)
    // Create two text files.
    Document doc1 = dte.ItemOperations.NewFile(@"General\Text File", 
        "Document1", Constants.vsViewKindPrimary).Document;
    dte.ItemOperations.NewFile(@"General\Text File", "Document2", 

    MessageBox.Show("The active window is " + 

    if (MessageBox.Show("Activate Document1?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)

    MessageBox.Show("The active window is " +