Share via


_DTE.ActiveDocument プロパティ

アクティブ ドキュメントを取得します。

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

構文

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

プロパティ値

型 : EnvDTE.Document
Document オブジェクト。

解説

アクティブ ドキュメントは、フォーカスのあるドキュメントです。 ほかのドキュメントをアクティブにするには、そのドキュメントのウィンドウにフォーカスを設定します。

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

アクティブ ドキュメントのプロパティは、プロジェクトの [プロパティ] のウィンドウが Microsoft Visual Studio 2005 で開いたときに例外をスローします。

重要

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

Sub ActiveDocumentExample()
  Dim objTextDoc As TextDocument
  Dim objEP As EditPoint
  
  'Create a new text document.
  Call DTE.ItemOperations.NewFile("General\Text File")
  'Get a handle to the new document.
  Set objTextDoc = DTE.ActiveDocument.Object("TextDocument")
  Set objEP = objTextDoc.StartPoint.CreateEditPoint
  'Create an EditPoint and add some text.
  objEP.Insert "A test sentence."
End Sub

Sub DocumentExample()
  Dim doc As Document
  Dim desc As String

  Set doc = DTE.ActiveDocument
  desc = "You are editing a "
  If (doc.ReadOnly) Then
    desc = desc & "read-only"
  Else
    desc = desc & "writable"
  End If
  desc = desc & " document called " & doc.Name & " located at " & doc.Path
  MsgBox desc
End Sub

重要

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

STDMETHODIMP CConnect::ActiveDocumentExample(DTE2 * pApplication)
{
CComPtr<ItemOperations> pItemOperations;
CComPtr<Document> pDocument;
CComPtr<Window> pDocWindow;
CComPtr<TextPoint> pTextPoint;
CComPtr<EditPoint> pEditPoint;
CComPtr<TextDocument> pTextDocument;
CComBSTR bstrFileName = "MyTextDocument";
CComBSTR bstrFileItem = "General\\Text File";
CComBSTR bstrFileText = "This is a line of text.";
CComBSTR bstrModelKind = "TextDocument";
CComPtr<IDispatch> pToolObject;
HRESULT hr = S_FALSE;

while (hr != S_OK && pApplication != nullptr) 
{
// create a document - it will be the new active document
pApplication->get_ItemOperations(&pItemOperations);
if (pItemOperations != nullptr) pItemOperations->NewFile(bstrFileItem,bstrFileName,_bstr_t(vsViewKindTextView),&pDocWindow); else break;

//get the current active document - use TextDocument interface so we can edit it
pApplication->get_ActiveDocument(&pDocument);
if (pDocument != nullptr) pDocument->Object(bstrModelKind, &pToolObject); else break;
if (pToolObject != nullptr) pToolObject->QueryInterface(__uuidof(TextDocument), (LPVOID*)&pTextDocument); else break;
if (pTextDocument != nullptr) pTextDocument->CreateEditPoint(pTextPoint,&pEditPoint); else break;
if (pEditPoint != nullptr) pEditPoint->Insert(bstrFileText); else break;

MessageBox(NULL, "Done, Active Document is new file. ", "Active Document Example", MB_OK);  
hr = S_OK;
return hr;
}
return hr;
}
STDMETHODIMP CConnect::DocumentExample(DTE2 * pApplication)
{
CComPtr<Document> pDocument;
CComBSTR bstrDesc;
CComBSTR bstrDocName;
CComBSTR bstrDocPath;
VARIANT_BOOL bReadOnly = false; 
HRESULT hr = S_FALSE;

while (hr != S_OK && pApplication != nullptr)
{
pApplication->get_ActiveDocument(&pDocument);
bstrDesc.Append("You are editing a ");
if (pDocument != nullptr) 
{
pDocument->get_ReadOnly(&bReadOnly);
pDocument->get_Name(&bstrDocName);
pDocument->get_Path(&bstrDocPath);
}
else break;
if (bReadOnly == true)
bstrDesc.Append("read-only");
else
bstrDesc.Append("writable");

bstrDesc.Append(" document called ");
bstrDesc.Append(bstrDocName);
bstrDesc.Append(" located at ");
bstrDesc.Append(bstrDocPath);

_bstr_t bstrIntermed = bstrDesc;
MessageBox(NULL,(LPCSTR) bstrIntermed,"Document Example",MB_OK); 
hr = S_OK;
return hr;
}
return hr;
}

.NET Framework セキュリティ

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

参照

関連項目

_DTE インターフェイス

EnvDTE 名前空間