查找本地化Windows字符串

Dou*_*ugN 5 windows localization

我需要找到当前版本的Windows正在使用的一些字符串.例如,当我创建一个新文件夹时,它最初在英文版Vista上命名为"新文件夹".我需要以编程方式查找在我可能正在运行的任何语言和Windows版本上命名该文件夹的内容.

任何人有任何想法如何做到这一点?

谢谢莫里纳尔 - 我也偶然发现了这篇文章.不幸的是,stringID似乎不是常量 - 在我的Vista上它是30396,这与它们为XP显示的不同.因此,MS似乎没有保持稳定.

编辑:看起来这是不可能的......?这个应用程序运行在德国,荷兰,法国,西班牙,巴西,墨西哥,越南,台湾,中国,日本,韩国,印度,以色列,匈牙利的计算机上......你明白了.安装所有不同的语言包需要很长时间,并找出每种语言中的"新文件夹".

也许最好的选择是默认为"新建文件夹",并让用户根据需要更改该值.我只是想让软件尽可能多地计算出来,并使用户无需配置_yet_another_setting_.

MSN*_*MSN 7

来自http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx的无耻贿赂.这大多是正确的,但如果有一个"New Folder something else"的资源字符串,它将匹配:

LPCWSTR FindStringResourceEx(HINSTANCE hinst,
    UINT uId, UINT langId)
{
    // Convert the string ID into a bundle number
    LPCWSTR pwsz = NULL;
    HRSRC hrsrc = FindResourceEx(hinst, RT_STRING,
        MAKEINTRESOURCE(uId / 16 + 1),
        langId);
    if (hrsrc) {
        HGLOBAL hglob = LoadResource(hinst, hrsrc);
        if (hglob) {
            pwsz = reinterpret_cast<LPCWSTR>
                (LockResource(hglob));
            if (pwsz) {
                // okay now walk the string table
                for (int i = 0; i < (uId & 15); i++) {
                    pwsz += 1 + (UINT)*pwsz;
                }

                pwsz+= 1;
            }
        }
    }
    return pwsz;
}

UINT FindResourceStringId(HMODULE resource_handle, LPCWSTR string, UINT langId)
{
    UINT resource_id= -1;

    for (int i= 0; i<65536; ++i)
    {
        LPCWSTR resource_string= FindStringResourceEx(resource_handle, i, langId);

        if (resource_string && wcsncmp(resource_string, string, wcslen(string))==0)
        {
            resource_id= i;
        }
    }

    return resource_id;
}

int main()
{
    HMODULE shell_handle= LoadLibraryW(L"shell32.dll");
    UINT new_folder_id= FindResourceStringId(shell_handle, L"New Folder", 0x409); // look for US English "New Folder" resource id.
}
Run Code Online (Sandbox Code Playgroud)

  • @DougN,你可以使用英语语言环境获取ID,然后使用`FindResourceStringEx(resource_handle,new_folder_id,language_id)`用于其他语言.0x409是英语的语言ID.因此,如果你想要简体中文,你可以使用`FindResourceStringEx(resource_handle,new_folder_id,0x0804)`,用于法语`FindResourceStringEx(resource_handle,new_folder_id,0x080c)`等. (4认同)

Luk*_*uke 5

这并不容易。这些字符串是 Windows 资源管理器的私有数据,因此它们可以(并且可能确实)在版本之间进行更改。您可以在进行大量版本检查并读取适当的资源字符串的情况下破解某些内容,但这似乎是一场失败的战斗。你想达到什么目的?