HTMLWindow3 接口

更新:2007 年 11 月

表示 Visual Studio 集成开发环境 (IDE) 中的 HTML 文档窗口。

命名空间:  EnvDTE90
程序集:  EnvDTE90(在 EnvDTE90.dll 中)

语法

声明
<GuidAttribute("BAD0A3DD-8109-4684-B806-A5282267BFE4")> _
Public Interface HTMLWindow3
用法
Dim instance As HTMLWindow3
[GuidAttribute("BAD0A3DD-8109-4684-B806-A5282267BFE4")]
public interface HTMLWindow3
[GuidAttribute(L"BAD0A3DD-8109-4684-B806-A5282267BFE4")]
public interface class HTMLWindow3
public interface HTMLWindow3

备注

当文档是 HTML 文档时,HTMLWindow3 由 Window 对象的 Object 属性返回。将 CurrentTab 属性设置为 vsHTMLTabsSource 时,Window.Selection 和 Document.Selection 返回一个 TextSelection 对象。

随着 Visual Studio 2008 HTML 编辑器中“拆分”视图的引入,增加了 HTMLWindow3、vsHTMLPanesvsHTMLViews。“拆分”视图将 HTML 编辑器窗口的选项卡和视图元素分隔开来。切换视图(到“设计”或“源”视图)并不一定意味着切换选项卡(“设计”/“拆分”/“源”)。例如,当您单击“拆分”选项卡时,在“设计”和“源”之间切换视图不会更改选项卡,而只会在“拆分”视图中激活或取消激活“设计”和“源”部分。

Visual Studio 2008 HTMLWindow 对象现在还实现 HTMLWindow3 接口,该接口返回当前视图(“设计”或“源”)和当前窗格(“设计”、“源”或“拆分”选项卡)。

HTMLWindow3 规则

HTMLWindow3 的行为是:

获取

当前窗格(选项卡)

当前视图返回

vsHTMLPaneDesign

vsHTMLViewDesign

vsHTMLPaneSource

vsHTMLViewSource

vsHTMLPaneSplit

vsHTMLViewDesignvsHTMLViewSource,具体取决于哪个部分处于活动状态。

设置

当前窗格(选项卡)

设置

vsHTMLPaneDesign

  • 如果将视图设置为 vsHTMLViewSource,或将窗格设置为 vsHTMLPaneSource,则会将 HTML 编辑器切换到“源”视图和“源”窗格。

  • 如果将窗格设置为 vsHTMLPaneSplit,则会将 HTML 编辑器切换到“设计”部分处于活动状态的“拆分”窗格。

vsHTMLPaneSource

  • 如果将视图设置为 vsHTMLViewDesign,或将窗格设置为 vsHTMLPaneDesign,则会将 HTML 编辑器切换到“设计”视图和“设计”窗格。

  • 如果将窗格设置为 vsHTMLPaneSplit,则会将 HTML 编辑器切换到“源”部分处于活动状态的“拆分”窗格。

vsHTMLPaneSplit

  • 如果将视图设置为 vsHTMLViewDesign,则会将编辑器切换到“拆分”窗格的“设计”部分。窗格不会更改为“设计”视图。

  • 如果将视图设置为 vsHTMLViewSource,则会将编辑器切换到“拆分”窗格的“源”部分。窗格不会更改为“源”窗格。

  • 如果将窗格设置为 vsHTMLPaneDesign,则会将编辑器切换到“设计”视图和“设计”窗格。

  • 如果将窗格设置为 vsHTMLPaneSource,则会将编辑器切换到“源”视图和“源”窗格。

示例

Sub HTMLWindow3Example(ByVal dte As EnvDTE80.DTE2)
    ' Open an HTML document before running this sample.
    If TypeOf dte.ActiveDocument.ActiveWindow.Object Is HTMLWindow3 _
        Then
            ' Ask the user for a file to insert into the body of the
            ' HTML document. This file should be an HTML fragment.
            Dim strFile As String = InputBox("Enter the name of a _
              file to insert at the end of the HTML document:")
            ' Get the HTMLWindow3 object and determine which tab is 
            ' currently active.
            Dim objHTMLWin As HTMLWindow3 = _
            CType(dte.ActiveDocument.ActiveWindow.Object, HTMLWindow3)
            Dim Tab As vsHTMLTabs = CType(objHTMLWin.CurrentTab, _
              vsHTMLTabs)
            Dim cpane As vsHTMLPanes = vsHTMLPanes.vsHTMLPaneSplit

            ' Switch to the "split" view, source view.
            objHTMLWin.CurrentPane = vsHTMLPanes.vsHTMLPaneSplit
            objHTMLWin.CurrentView = vsHTMLViews.vsHTMLViewSource

            ' Get an EditPoint at the start of the text.
            Dim objTextWin As TextWindow = _
              CType(objHTMLWin.CurrentTabObject, TextWindow)
            Dim objEP As EditPoint = _
            objTextWin.ActivePane.StartPoint.CreateEditPoint

            ' Look for the end of the document body.
            If objEP.FindPattern("</body>") Then
                ' Insert the contents of the file.
                objEP.InsertFromFile(strFile)
            End If

            ' Switch back to the original view of the HTML file.
            'objHTMLWin.CurrentTab = Tab
        Else
            MsgBox("You must open an HTML document.")
        End If
    End Sub
public void HTMLWindowExample(_DTE dte)
{
    // Open an HTML document before running this sample.
    if (dte.ActiveDocument.ActiveWindow.Object is HTMLWindow3)
    {
        HTMLWindow3 objHTMLWin;
        vsHTMLTabs Tab;
        String strFileName;
        // Ask the user for a file to insert into the body of the HTML 
        // document. This file should be an HTML fragment.
        strFileName = Microsoft.VisualBasic.Interaction.InputBox 
        ("Enter the name of a file to insert at the end of the HTML 
        document:","","",100,100);
        // Get the HTMLWindow3 object and determine which tab is 
        // currently active.
        objHTMLWin = dte.ActiveDocument.ActiveWindow.Object as 
        HTMLWindow3;
        Tab = objHTMLWin.CurrentTab;

        // Switch to the "source" tab.
        objHTMLWin.CurrentPane = vsHTMLPanes.vsHTMLPaneSplit;
        objHTMLWin.CurrentTab = vsHTMLViews.vsHTMLViewSource;

        // Get an EditPoint at the start of the text.
        TextWindow objTextWin;
        EditPoint ep;
        EditPoint ep2 = null;
        TextRanges textRanges = null;
        objTextWin = objHTMLWin.CurrentTabObject as TextWindow;
        ep = objTextWin.ActivePane.StartPoint.CreateEditPoint();
        textRanges = objTextWin.Selection.TextRanges;

        // Look for the end of the document body.
        if (ep.FindPattern 
        ("</body>",(int)vsFindOptions.vsFindOptionsNone, ref ep2, ref 
        textRanges))
            // Insert the contents of the file.
            ep.InsertFromFile (strFileName);
            // Switch back to the original view of the HTML file.
            objHTMLWin.CurrentTab = Tab;
    }
    else
        MessageBox.Show ("You must open an HTML document.");
}

另请参见

参考

HTMLWindow3 成员

EnvDTE90 命名空间