Windows跳过特定于语言的资源

时间:2011-05-17 22:15:11

标签: winapi resources localization internationalization

我正在使用Windows API,我正在尝试使用多语言资源来加载特定于语言的菜单和内容。但是,出于某种原因,如果有美国英语替代品,Windows绝对拒绝加载波斯尼亚语(拉丁语)资源。通过FindResourceEx加载资源。我在XP SP3上,波斯尼亚语(拉丁语)在我的区域设置中设置。

的main.c

#include <Windows.h>
#include "resource.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PTSTR pCmdLine, int nCmdShow)
{
    TCHAR string[64];

    /* Message box properly outputs "This is German (DE)." here. */
    SetThreadLocale(MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT));
    LoadString(hInstance, TEST_STRING, string, sizeof(string)/sizeof(string[0]));
    MessageBox(NULL, string, TEXT("Message"), MB_OK);

    /* Message box outputs "This is English (US)." - WTF?! */
    SetThreadLocale(MAKELCID(MAKELANGID(LANG_BOSNIAN, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN), SORT_DEFAULT));
    LoadString(hInstance, TEST_STRING, string, sizeof(string)/sizeof(string[0]));
    MessageBox(NULL, string, TEXT("Message"), MB_OK);

    return 0;
}

resources.rc

#include <windows.h>
#include "resource.h"

LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
STRINGTABLE
{
    TEST_STRING                   "This is English (US)."
}

LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
STRINGTABLE
{
    TEST_STRING                   "This is German (DE)."
}

LANGUAGE LANG_BOSNIAN, SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN
STRINGTABLE
{
    TEST_STRING                   "This is Bosnian (Latin)."
}

LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
STRINGTABLE
{
    TEST_STRING                   "This is French (FR)."
}

RESOURCE.H

#define TEST_STRING                             40000

1 个答案:

答案 0 :(得分:1)

LoadString中的语言选择机制(以及通常所有资源检索API)从Vista开始被破坏(因为系统级别添加了MUI机制)。

目前最好的做法是将每种语言存储在单独的资源中,并使用DLL的hInstance访问资源。您可以自己加载dll,或使用较新的MUI API来执行此操作(http://msdn.microsoft.com/library/dd319076%28VS.85%29.aspx