次の方法で共有


_DTE.ActiveWindow プロパティ

現在アクティブなウィンドウ、または他にアクティブなウィンドウがない場合は最前面に表示されたウィンドウを返します。

名前空間:  EnvDTE
アセンブリ:  EnvDTE (EnvDTE.dll 内)

構文

'宣言
ReadOnly Property ActiveWindow As Window
Window ActiveWindow { get; }
property Window^ ActiveWindow {
    Window^ get ();
}
abstract ActiveWindow : Window with get
function get ActiveWindow () : Window

プロパティ値

型 : EnvDTE.Window
Window オブジェクト。開いているウィンドウがない場合は、Nothing を返します。

解説

ActiveWindow は、その環境のアクティブなウィンドウを返します。

キャプションを設定できるのはツール ウィンドウだけです。 ドキュメント ウィンドウなど、他の種類のウィンドウにキャプションを設定しようとすると、"予期しないエラーです" というエラーが表示されます。

重要

読みやすさのために、次のコード例は、チェックするセキュリティが含まれていないか、エラー処理を完了しません。稼動環境で次のコードを使用します。

Sub ActiveWindowExample(ByVal dte As DTE2)

    ' Create two text files.
    Dim doc1 As Document = _
        dte.ItemOperations.NewFile(, "Document1").Document
    dte.ItemOperations.NewFile(, "Document2")

    MsgBox("The active window is " & dte.ActiveWindow.Caption)

    If MsgBox("Activate Document1?", MsgBoxStyle.YesNo) = _
        MsgBoxResult.Yes Then
        doc1.Activate()
    End If

    MsgBox("The active window is " & dte.ActiveWindow.Caption)

End Sub

重要

読みやすさのために、次のコード例は、チェックするセキュリティが含まれていないか、エラー処理を完了しません。稼動環境で次のコードを使用します。

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", 
        Constants.vsViewKindPrimary);

    MessageBox.Show("The active window is " + 
        dte.ActiveWindow.Caption);

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

    MessageBox.Show("The active window is " + 
        dte.ActiveWindow.Caption);
}

重要

読みやすさのために、次のコード例は、チェックするセキュリティが含まれていないか、エラー処理を完了しません。稼動環境で次のコードを使用します。

STDMETHODIMP CConnect::ActiveWindowExample(DTE2 * pApplication)
{
CComPtr<ItemOperations> pItemOperations;
CComPtr<Document> pDocument;
CComPtr<Window> pDocWindow;
CComPtr<Window> pDoc1Window;
CComPtr<Window> pDoc2Window;
CComBSTR bstrDesc;
CComBSTR bstrDocWindow;
CComBSTR bstrFile1Name = "MyDocument1";
CComBSTR bstrFile2Name = "MyDocument2";
CComBSTR bstrFileItem = "General\\Text File";
VARIANT_BOOL bReadOnly = false; 
HRESULT hr = S_FALSE;

while (hr != S_OK && pApplication != nullptr)
{
// create two text files
pApplication->get_ItemOperations(&pItemOperations);
if (pItemOperations != nullptr) pItemOperations->NewFile(bstrFileItem,bstrFile1Name,_bstr_t(vsViewKindTextView),&pDoc1Window); else break;
if (pItemOperations != nullptr) pItemOperations->NewFile(bstrFileItem,bstrFile2Name,_bstr_t(vsViewKindTextView),&pDoc2Window); else break;

//get the current active window 
pApplication->get_ActiveWindow(&pDocWindow);
if (pDocWindow != nullptr) pDocWindow->get_Caption(&bstrDocWindow); else break;
bstrDesc.Append("The active window is ");
bstrDesc.Append(bstrDocWindow);
_bstr_t bstrIntermed = bstrDesc;
MessageBox(NULL,(LPCSTR) bstrIntermed,"Active Window Example",MB_OK);
bstrDesc = "";

pDocWindow = nullptr;
if (MessageBox(NULL,"Activate Document1?", "", MB_YESNO) == IDYES) pDoc1Window->Activate();
//get the current active window 
pApplication->get_ActiveWindow(&pDocWindow);
if (pDocWindow != nullptr) pDocWindow->get_Caption(&bstrDocWindow); else break;
bstrDesc.Append("The active window is ");
bstrDesc.Append(bstrDocWindow);
bstrIntermed = bstrDesc;
MessageBox(NULL,(LPCSTR) bstrIntermed,"Active Window Example",MB_OK);

hr = S_OK;
return hr;

}
return hr;
}

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

_DTE インターフェイス

EnvDTE 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する