Find localized Windows strings

后端 未结 4 1619
逝去的感伤
逝去的感伤 2021-01-12 20:47

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

4条回答
  •  自闭症患者
    2021-01-12 21:26

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

提交回复
热议问题