查找本地化的Windows字符串

查找本地化的Windows字符串

本文介绍了查找本地化的Windows字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to find some strings that the current version of Windows is using. For example, when I create a new folder, it is initially named "New Folder" on English Vista. I need to programmatically find what that folder would be named on any language and version of Windows that I might be running on.

任何人都知道该怎么做吗?

Anyone have any ideas how to do that?

感谢Morinar-我也偶然发现了这篇文章.不幸的是,stringID似乎不是恒定的-在我的Vista中是30396,这与XP中显示的相同.因此,看来MS不能使其保持稳定.

Thanks Morinar -- I just stumbled upon that article too. Unfortunately, the stringID doesn't appear to be constant -- it's 30396 on my Vista, which isn't the same as what they show for XP. So it would appear MS didn't keep it stable.

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

Looks like this isn't possible...? This apps runs on computers in Germany, The Netherlands, France, Spain, Brazil, Mexico, Vietnam, Taiwan, China, Japan, South Korea, India, Israel, Hungary ... You get the idea. It will take a very long time to install all the different language packs and find out what 'New Folder' is in every language.

也许最好的选择是默认为新文件夹",并让用户根据需要更改该值.我只是更喜欢让软件尽其所能,并避免用户配置_yet_another_setting _.

Perhaps the best option is to default to "New Folder" and make the user change that value if they want to. I just prefer to have the software figure out as much as it can and spare the user from configuring _yet_another_setting_.

推荐答案

http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx .多数情况下这是正确的,但是如果资源字符串为其他新文件夹",它将与该字符串匹配:

Shamelessly cribbed from http://blogs.msdn.com/oldnewthing/archive/2004/01/30/65013.aspx. This is mostly correct but if there is a resource string of "New Folder something else" it will match that:

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.
}

这篇关于查找本地化的Windows字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 14:36