Reputation: 13378
I have an MFC project that contains one .rc file for US English, and one .rc file for Swiss German. The two .rc files are identical except for 1) a single string that I am using for my tests, and 2) the .rc files use different LANGUAGE
statements at the top:
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US >>> for US English
LANGUAGE LANG_GERMAN, SUBLANG_GERMAN_SWISS >>> for Swiss German
I am including the two .rc files from a single main .rc file. The main .rc file is compiled, the language-specific .rc files are set to "exclude from build".
I believe I have setup everything correctly, because I can use a snippet like the following to successfully load a string resource from the Swiss German language resource file:
WORD swissGermanLanguageID =
MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS);
WORD swissGermanLCID =
MAKELCID(swissGermanLanguageID, SORT_DEFAULT);
CString teststring;
teststring.LoadString(AfxGetResourceHandle(), IDS_TESTSTRING, swissGermanLCID);
The problem is: When I omit the language ID, such as in the following snippet, MFC always loads the resource from the US English resources, no matter what I try:
CString teststring;
teststring.LoadString(IDS_TESTSTRING);
Things that I have tried/checked:
LoadString
successfully loads the Swiss German test string. My conclusion is that if present the US English resources have precedence over the Swiss German resource./l 0x0807
which corresponds to Swiss German.AfxSetResourceHandle()
behind the scene.OK, so finally, here's the question: How does MFC determine the default language ID that it uses when it loads resources? And even better: How can I change that default language ID?
Here's the snippet I mentioned above that I'm using to set the thread locale:
WORD swissGermanLanguageID =
MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS);
WORD swissGermanLCID =
MAKELCID(swissGermanLanguageID, SORT_DEFAULT);
SetThreadLocale(swissGermanLCID);
Upvotes: 4
Views: 2162
Reputation: 37550
GetThreadPreferredUILanguages
family of functions (there are a separate list for user, for process and for thread that get combined to perform resource lookup). Potentially it may be altered by MFC runtime, but I'm not sure about it. On your system this list will probably contain 4 entries: [de-CH
, de
, en-US
, en
].Upvotes: 2