Visual Studio 自动化模型提供 DTE 对象启用 Vspackage 访问在 工具 菜单的 选项 对话框。
通常,使用自动化模型,在 选项 对话框的页中访问, VSPackage 是否提供页。 Visual Studio (IDE) 集成开发环境 (ide) 或。 但是,有一些异常,如下所示:
动态帮助 页的设置不能通过编程方式访问。 动态帮助 功能可以控制的使用自动化模型,但是,直接在代码必须完成控件。 有关更多信息,请参见 How to: Control the Dynamic Help Window。
字体和颜色 页导航的控件提供通过自己的 API,不通过自动化模型。 有关更多信息,请参见 字体。
语言特定的属性不能通过自动化模型获取。
不支持 Visual Studio 自动化模型的选项 页可能不返回自动 Properties 集合,当查询。 如果集合返回,并不是所有的函数存在。 有关如何管理这些功能的信息,请参见 DTE 属性集合。
管理的选项卡页
若要管理 选项 页, VSPackage 必须捕获自动化模型中的一 DTE 对象。
备注
在 VSPackage 使用自动化模型查询和更改在安装的 选项 页中的设置,它不扩展 IDE 功能。因此,包不必实现自动化对象。
通过自动化模型若要获取 DTE 对象,请调用 QueryService 方法并提供 SID_SDTE 的服务标识符参数和 IID__DTE的接口参数,如下所示。
pServiceProvider->QueryService(SID_SDTE, IID__DTE, (LPVOID*)pDTE);
使用托管包结构,若要获取 DTE 对象 (MPF),请调用 GetService 方法并提供类型 SDTE的 serviceType 参数。
Dim vsEnvironment As DTE = DirectCast(GetService(GetType(SDTE)), DTE)
DTE vsEnvironment = (DTE)GetService(typeof(SDTE));
选项 页由两个标识符指定。 第一个标识符是指示文件夹包含 选项 页的字符串。 第二个标识符是指示该文件夹中的特定项的字符串。 这些引用 选项 页类别和子类别、其主题和子主题。
例如,进程的基本代码文本编辑器设置在导航窗格中为 文本编辑器 文件夹的 基本 成员。 类别的标识符是 TextEditor ,并且其子类别是 Basic,并且, 选项 页引用 TextEditor.Basic 页。
备注
为本地化和其他原因,在 选项 页中显示的名称可能与类别和子类别标识符使用的字符串不同。,如果它们在其他地方,无文档您可能需要使用自动化查询 IDE 获取正确的标识符。注册表位置为 \SOFTWARE\Microsoft\VisualStudio HKEY_LOCAL_MACHINE \VS Version\AutomationProperties,其中 VS Version 是 Visual Studio版本的版本号。有关更多信息,请参见 注册自定义选项卡页。
使用下面的示例中,您可以通过自动化模型获取 TextEditor.Basic 页的属性。
CComPtr<_DTE> srpDTE;
CComPtr<Properties> srpDTEPropertiesList;
hr = srpDTE->get_Properties("TextEditor", "Basic", &srpDTEPropertiesList);
使用 MPF,若要获取属性,请使用 Properties 方法。
Dim propertiesList As Properties = vsEnvironment.get_Properties("TextEditor", "Basic")
If propertiesList Is Nothing Then
' The specified properties collection is not available.
Exit Sub
End If
Properties propertiesList = vsEnvironment.get_Properties("TextEditor", "Basic");
if (null == propertiesList)
{
// The specified properties collection is not available.
return;
}
Item 方法返回从 Properties 集合的各个设置为 Property 对象。
与类别和子类别,每个组具有是一个字符串的标识符。 例如,若要在 TextEditor.Basic 页的 制表符大小 由个字符串, TabSize确定的。
备注
为本地化和其他原因,在 选项 页中显示的名称可能与设置标识符使用的字符串不同。,如果它们在其他地方,无文档您可能需要使用自动化查询 IDE 获取正确的标识符。
可以使用 Properties 集合 Item 方法返回查询和更改设置状态 Property 对象的 Value 。
例如,设置在 TextEditor.Basic 页的 制表符大小 通过自动化模型,请使用返回的 Properties 对象在下面的示例。
CComPtr<Property> srpProperty;
hr = srpDTEPropertiesList->Item("TabSize", &srpProperty);
hr= srpProperty.set_Value(4);
下面的示例演示如何设置更新使用 MPF 的 制表符大小 。
Dim tabSize As [Property] = propertiesList.Item("TabSize")
Dim oldSize As Short = CShort(tabSize.Value)
Dim message As String
If oldSize <> 4 Then
tabSize.Value = 4
message = String.Format(CultureInfo.CurrentUICulture, "For Basic, the Text Editor had a tab size of {0}" & " and now has a tab size of {1}.", oldSize, tabSize.Value)
Else
message = String.Format(CultureInfo.CurrentUICulture, "For Basic, the Text Editor has a tab size of {0}.", tabSize.Value)
End If
Property tabSize = propertiesList.Item("TabSize");
short oldSize = (short)tabSize.Value;
string message;
if (oldSize != 4)
{
tabSize.Value = 4;
message = string.Format(CultureInfo.CurrentUICulture,
"For Basic, the Text Editor had a tab size of {0}" +
" and now has a tab size of {1}.", oldSize, tabSize.Value);
}
else
{
message = string.Format(CultureInfo.CurrentUICulture,
"For Basic, the Text Editor has a tab size of {0}.", tabSize.Value);
}
MessageBox.Show(message, "Text Editor, Basic, Tab Size:",
MessageBoxButtons.OK, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, 0);
有关更多信息,请参见 控制选项设置。
保留的选项卡页导航
IDE 实现的 选项 页状态持久性完全支持 Visual Studio 自动化模型。
在 IDE 中包含的页的设置自动保存 (或检索),当用户在 工具 菜单中单击 导入/导出设置 命令。
可以使自定义 选项 页使用此自动持久性通过添加 ProfileSave 标志支持到自定义 选项 页注册表项在 HKEY_LOCAL_MACHINE \ \SOFTWARE\Microsoft\VisualStudioVS Version\AutomationProperties 下,其中 VS Version 是 Visual Studio版本的版本号。 有关更多信息,请参见 注册自定义选项卡页。