IDWriteFontFamily::GetFamilyNames-Methode (dwrite.h)

Erstellt ein lokalisiertes Zeichenfolgenobjekt, das die Familiennamen für die Schriftartenfamilie enthält, die nach Gebietsschemanamen indiziert sind.

Syntax

HRESULT GetFamilyNames(
  [out] IDWriteLocalizedStrings **names
);

Parameter

[out] names

Typ: IDWriteLocalizedStrings**

Die Adresse eines Zeigers auf das neu erstellte IDWriteLocalizedStrings-Objekt .

Rückgabewert

Typ: HRESULT

Wenn diese Methode erfolgreich ist, wird S_OK zurückgegeben. Andernfalls wird ein Fehlercode HRESULT zurückgegeben.

Hinweise

Im folgenden Codebeispiel wird gezeigt, wie Sie den Namen der Schriftfamilie aus einem IDWriteFontFamily-Objekt abrufen.

IDWriteLocalizedStrings* pFamilyNames = NULL;

// Get a list of localized strings for the family name.
if (SUCCEEDED(hr))
{
    hr = pFontFamily->GetFamilyNames(&pFamilyNames);
}

UINT32 index = 0;
BOOL exists = false;

wchar_t localeName[LOCALE_NAME_MAX_LENGTH];

if (SUCCEEDED(hr))
{
    // Get the default locale for this user.
    int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);

    // If the default locale is returned, find that locale name, otherwise use "en-us".
    if (defaultLocaleSuccess)
    {
        hr = pFamilyNames->FindLocaleName(localeName, &index, &exists);
    }
    if (SUCCEEDED(hr) && !exists) // if the above find did not find a match, retry with US English
    {
        hr = pFamilyNames->FindLocaleName(L"en-us", &index, &exists);
    }
}

// If the specified locale doesn't exist, select the first on the list.
if (!exists)
    index = 0;

UINT32 length = 0;

// Get the string length.
if (SUCCEEDED(hr))
{
    hr = pFamilyNames->GetStringLength(index, &length);
}

// Allocate a string big enough to hold the name.
wchar_t* name = new (std::nothrow) wchar_t[length+1];
if (name == NULL)
{
    hr = E_OUTOFMEMORY;
}

// Get the family name.
if (SUCCEEDED(hr))
{
    hr = pFamilyNames->GetString(index, name, length+1);
}

Anforderungen

   
Unterstützte Mindestversion (Client) Windows 7, Windows Vista mit SP2 und Plattformupdate für Windows Vista [Desktop-Apps | UWP-Apps]
Unterstützte Mindestversion (Server) Windows Server 2008 R2, Windows Server 2008 mit SP2 und Plattformupdate für Windows Server 2008 [Desktop-Apps | UWP-Apps]
Zielplattform Windows
Kopfzeile dwrite.h
Bibliothek Dwrite.lib
DLL Dwrite.dll

Weitere Informationen

IDWriteFontFamily