Udostępnij za pośrednictwem


How to: Access the Built-in Fonts and Color Scheme

The Visual Studio integrated development environment (IDE) has a scheme of fonts and colors that is associated with the editor window. You can access this scheme through the IVsTextView interface.

To use the built-in fonts and colors scheme, a VSPackage must:

  • Define a category to use with the default fonts and colors service.

  • Register the category with the default fonts and colors server.

  • Advise the IDE that a specific window uses the built-in display items and categories by using the T:Microsoft.VisualStudio.TextManager.Interop.IVsTextEditorPropertyCategoryContainer and T:Microsoft.VisualStudio.TextManager.Interop.IVsTextEditorPropertyContainer interfaces.

The IDE uses the resulting category as a handle to the window. The category's name is displayed in the Show settings for: drop-down box in the Fonts and Colors property page.

To define a category using built-in fonts and colors

  1. Create an arbitrary GUID.

    This GUID is used to uniquely identify a category**.** This category reuses the IDE's default fonts and colors specification. For more information, see GUIDGEN Sample: Generates Globally Unique Identifiers (GUIDs).

    Note

    When retrieving font and color data with the IVsFontAndColorEvents or other interfaces, VSPackages use this GUID to reference built-in information.

  2. The category's name must be added to a string table inside the VSPackage's resources (.rc) file, so that it can be localized as needed when displayed in the IDE.

    For more information, see Adding or Deleting a String.

To register a category using built-in fonts and colors

  1. Construct a special type of category registry entry in the following location:

    [HKLM\SOFTWARE\Microsoft \Visual Studio\<Visual Studio version>\FontAndColors\<Category>]

    <Category> is the non-localized name of the category.

  2. Populate the registry to use the stock fonts and color scheme with four values:

    Name

    Type

    Data

    Description

    Category

    REG_SZ

    GUID

    An arbitrary GUID that identifies a category that contains the stock font and color scheme.

    Package

    REG_SZ

    GUID

    {F5E7E71D-1401-11D1-883B-0000F87579D2}

    This GUID is used by all VSPackages that use the default font and color configurations.

    NameID

    REG_DWORD

    ID

    The resource ID of a localizable category name in the VSPackage.

    ToolWindowPackage

    REG_SZ

    GUID

    The GUID of the VSPackage implementing the IVsTextView interface.

To initiate the use of system-provided fonts and colors

  1. Create an instance of the T:Microsoft.VisualStudio.TextManager.Interop.IVsTextEditorPropertyCategoryContainer interface as part of the window's implementation and initialization.

  2. Call the GetPropertyCategory method to obtain an instance of the T:Microsoft.VisualStudio.TextManager.Interop.IVsTextEditorPropertyContainer interface corresponding to the current IVsTextView instance.

  3. Call SetProperty twice.

    • Call once with VSEDITPROPID_ViewGeneral_ColorCategoryas an argument.

    • Call once with VSEDITPROPID_ViewGeneral_FontCategory as an argument.

    This sets and exposes the default fonts and colors services as a property of the window.

Example

The following example initiates the use of built-in fonts and colors.

CComVariant vt;
CComQIPtr<IVsTextEditorPropertyCategoryContainer> spPropCatContainer(m_spView);
if (spPropCatContainer != NULL){
    CComPtr<IVsTextEditorPropertyContainer> spPropContainer;
    if (SUCCEEDED(spPropCatContainer->GetPropertyCategory(GUID_EditPropCategory_View_MasterSettings, 
                                                          &spPropContainer))){
        CComVariant vt;CComVariant VariantGUID(bstrGuidText);
        spPropContainer->SetProperty(VSEDITPROPID_ViewGeneral_FontCategory, VariantGUID);
        spPropContainer->SetProperty(VSEDITPROPID_ViewGeneral_ColorCategory, VariantGUID);
    }
}

See Also

Concepts

Getting Font and Color Information for Text Colorization

Accessing Stored Font and Color Settings

Font and Color Overview

Other Resources

Fonts