_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 개체

설명

활성 문서는 포커스가 있는 문서입니다. 다른 문서를 활성 문서로 만들려면 포커스를 해당 창에 설정합니다.

도구 창에서만 캡션을 설정할 수 있습니다. 문서 창 등의 다른 창 형식에서 캡션을 설정하려고 시도하는 경우, "알 수 없는 오류입니다"라는 오류가 나타납니다.

현재 문서의 속성에서 예외를 throw 하면 프로젝트 속성 창을 열면 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 네임스페이스