IDWriteLocalizedStrings 介面 (dwrite.h)

表示以地區設定名稱編製索引的字串集合。

繼承

IDWriteLocalizedStrings 介面繼承自 IUnknown 介面。 IDWriteLocalizedStrings 也有下列類型的成員:

方法

IDWriteLocalizedStrings 介面具有這些方法。

 
IDWriteLocalizedStrings::FindLocaleName

取得地區設定名稱/字串組與指定地區設定名稱之以零起始的索引。
IDWriteLocalizedStrings::GetCount

取得語言/字串組的數目。
IDWriteLocalizedStrings::GetLocaleName

將具有指定索引的地區設定名稱複製到指定的陣列。 (IDWriteLocalizedStrings.GetLocaleName)
IDWriteLocalizedStrings::GetLocaleNameLength

取得字元的長度, (不包含具有指定索引之地區設定名稱的 null 終止符) 。 (IDWriteLocalizedStrings.GetLocaleNameLength)
IDWriteLocalizedStrings::GetString

將具有指定索引的字串複製到指定的陣列。 (IDWriteLocalizedStrings.GetString)
IDWriteLocalizedStrings::GetStringLength

取得字元長度, (不包含具有指定索引之字串的 null 終止符) 。 (IDWriteLocalizedStrings.GetStringLength)

備註

IDWriteLocalizedStrings 所代表的字串集會以零起始的 UINT32 數位編制索引,以對應至地區設定。 特定地區設定的數值索引會使用 FindLocaleName 方法來復原。

IDWriteLocalizedStrings 介面的常見用法是保存使用IDWriteFontFamily::GetFamilyNames 方法所建立的當地語系化字型系列名稱清單。 下列範例示範如何取得 「en-us」 地區設定的系列名稱。

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);
}

規格需求

需求
最低支援的用戶端 適用於 Windows Vista 的 Windows 7、Windows Vista SP2 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 dwrite.h