You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

切换线程语言后如何正确获取对应语言的文件属性?

问题:获取特定语言的文件属性文本异常

多数文件文本属性为可读写,不受当前线程语言影响;但部分只读属性会受语言影响,例如已知文件夹名称、Shell项类型属性PKEY_ItemType与PKEY_ItemTypeText,这类属性还有很多。

我的电脑安装了英文和泰文,当前系统语言为英文。切换线程语言后,调用IPropertyStore::GetValue()获取属性值的结果异常:有时能返回对应语言的文本,有时却不能。我希望使用IPropertyStore::GetValue()或替代方法,获取线程当前语言对应的属性文本。

复现问题的控制台程序

#include <iostream>
#include <objbase.h>
#include <propkey.h>
#include <Shlobj.h>

void ShowProperty(const WCHAR *pczDesc, LPITEMIDLIST pidlItem, const PROPERTYKEY& infoKey)
{
    IPropertyStore         *pIStore;
    PROPVARIANT             propValue;

    if(SHGetPropertyStoreFromIDList(pidlItem, GPS_DEFAULT, IID_IPropertyStore, (void **)&pIStore) == S_OK)
    {
        PropVariantInit(&propValue);
    
        if(pIStore->GetValue(infoKey, &propValue) == S_OK)
        {
            wprintf(L"%s<%s>\n", pczDesc, propValue.bstrVal);

            PropVariantClear(&propValue);
        }

        if(pIStore != NULL)
        {
            pIStore->Release();
        }
    }
}

int main()
{
    LANGID          nLangPC;
    LANGID          nLang2;
    LPITEMIDLIST    pidlSystem32;
    LPITEMIDLIST    pidlKnownFolder;

    CoInitialize(nullptr);

    nLang2  = 0x041E; // 泰文
    nLangPC = GetThreadUILanguage();

    if((pidlSystem32 = ILCreateFromPath(L"C:\\Windows\\System32")) != NULL)
    {
        if(SHGetKnownFolderIDList(FOLDERID_Music, KF_FLAG_DEFAULT, NULL, &pidlKnownFolder) == S_OK)
        {
            wprintf(L"\n------- 0x%04X ------------\n", nLang2);

            SetThreadUILanguage(nLang2);

            ShowProperty(L"System32 folder name:      ", pidlSystem32,    PKEY_ItemNameDisplay);
            ShowProperty(L"System32 folder type:      ", pidlSystem32,    PKEY_ItemType);
            ShowProperty(L"System32 folder type text: ", pidlSystem32,    PKEY_ItemTypeText);
            ShowProperty(L"Known folder name:         ", pidlKnownFolder, PKEY_ItemNameDisplay);
            ShowProperty(L"Known folder type:         ", pidlKnownFolder, PKEY_ItemType);
            ShowProperty(L"Known folder type text:    ", pidlKnownFolder, PKEY_ItemTypeText);

            wprintf(L"\n------- 0x%04X ------------\n", nLangPC);

            SetThreadUILanguage(nLangPC);

            ShowProperty(L"System32 folder name:      ", pidlSystem32,    PKEY_ItemNameDisplay);
            ShowProperty(L"System32 folder type:      ", pidlSystem32,    PKEY_ItemType);
            ShowProperty(L"System32 folder type text: ", pidlSystem32,    PKEY_ItemTypeText);
            ShowProperty(L"Known folder name:         ", pidlKnownFolder, PKEY_ItemNameDisplay);
            ShowProperty(L"Known folder type:         ", pidlKnownFolder, PKEY_ItemType);
            ShowProperty(L"Known folder type text:    ", pidlKnownFolder, PKEY_ItemTypeText);

            ILFree(pidlKnownFolder);
        }

        ILFree(pidlSystem32);
    }

    CoUninitialize();
    return 0;
}

输出结果及正误标注

------- 0x041E ------------
System32 folder name:      <System32>      - 正确
System32 folder type:      <Directory>     - 错误
System32 folder type text: <โฟลเดอร์แฟ้ม>    - 正确
Known folder name:         <เพลง>          - 正确
Known folder type:         <Directory>     - 错误
Known folder type text:    <โฟลเดอร์ระบบ>   - 正确

------- 0x0809 ------------
System32 folder name:      <System32>       - 正确
System32 folder type:      <Directory>      - 正确
System32 folder type text: <โฟลเดอร์แฟ้ม>     - 错误
Known folder name:         <เพลง>           - 错误
Known folder type:         <Directory>      - 正确
Known folder type text:    <System Folder>  - 正确

内容的提问来源于stack exchange,提问作者davecupper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 03:27:04