次の方法で共有


方法 : コマンド ウィンドウを制御する

Visual Studio アドインは、Visual Studio 2013 では使用されなくなりました。 アドインを VSPackage 拡張機能にアップグレードしてください。 アップグレードの詳細については、「FAQ: アドインを VSPackage 拡張に変換する」を参照してください。

CommandWindow オブジェクトは、Visual Studio オートメーション モデルの [コマンド ウィンドウ] を表します。 CommandWindow オブジェクトは、次の用途に使用できます。

  • [コマンド ウィンドウ] にコマンドを挿入します。SendInput メソッドを使用することにより、そのコマンドを実行することもできます。

  • OutputString メソッドを使用して、情報テキストを [コマンド ウィンドウ] に挿入します。

  • Clear メソッドを使用して、[コマンド ウィンドウ] からテキストをすべて消去します。

[コマンド ウィンドウ] の内容を制御するだけでなく、幅や高さなどの [コマンド ウィンドウ] の特性も制御できます。 詳細については、「方法 : ウィンドウの特性を変更する」を参照してください。

注意

実際に画面に表示されるダイアログ ボックスとメニュー コマンドは、アクティブな設定またはエディションによっては、ヘルプの説明と異なる場合があります。ここに記載されている手順は、全般的な開発設定が適用されているものとして記述されています。設定を変更するには、[ツール] メニューの [設定のインポートとエクスポート] をクリックします。詳細については、「Visual Studio での開発設定のカスタマイズ」を参照してください。

使用例

次の例では、[コマンド ウィンドウ] オートメーション モデルのさまざまなメンバーを参照および使用する方法を示します。 この例の実行方法の詳細については、「方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する」を参照してください。

Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, _
  ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    CommandWinExample(_applicationObject)
End Sub

Sub CommandWinExample(ByVal dte As DTE2)
    Try
        ' Get a reference to the Command window.
        Dim CW As CommandWindow = dte.ToolWindows.CommandWindow

        ' Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.")

        ' Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", True)

        ' Clear the contents of the Command window.
        MsgBox("Clearing the Command window...")
        CW.Clear()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
public void OnConnection(object application, ext_ConnectMode 
  connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    CommandWinExample(_applicationObject);
}

public void CommandWinExample(DTE2 dte)
{
    try
    {
        // Get a reference to the Command window.
        CommandWindow CW = dte.ToolWindows.CommandWindow;

        // Insert informative text into the Command window.
        CW.OutputString("This takes you to the Microsoft Web site.");

        // Add a command to the Command window and execute it.
        CW.SendInput("nav https://www.microsoft.com", true);

        // Clear the contents of the Command window.
        System.Windows.Forms.MessageBox.Show(
          "Clearing the Command window...");
        CW.Clear();
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message);
    }
}

参照

処理手順

方法 : ウィンドウの特性を変更する

方法 : アドインを作成する

チュートリアル : ウィザードの作成

概念

オートメーション オブジェクト モデルの階層図

その他の技術情報

環境ウィンドウの作成と制御

アドインおよびウィザードの作成

オートメーションと機能拡張のリファレンス