近来学习”多语言的设置”时,查看MSDN的SetThreadLocaleFunction网页时有如此:
Windows Vista and later:Do notuseSetThreadLocaleto select a user interface language. The resource loader selects the resourcethat is defined in the .rc file with a LANGUAGE statement, or the applicationcan useFindResourceEx. Additionally, theapplication can useSetThreadUILanguage.
Windows 2000,Windows XP: Do not use SetThreadLocaleto select a user interface language. To select the resource that is defined inthe .rc file with a LANGUAGE statement, the application must use theFindResourceEx function.
具体的代码实现如下|
LCID GetDefaultLCID()
{
LCID lcid = GetUserDefaultLCID();
HKEY hKey;
if(gFaxName.IsEmpty())
{
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, SWPACKET_VERSION, 0, KEY_QUERY_VALUE, &hKey))
{
return lcid;
}
}
else
{
CString regkey;
regkey=COMMONREGKEY;
regkey.Append(_T("\\"));
regkey.Append(gFaxName);
regkey.Append(_T("\\Version"));
if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, KEY_QUERY_VALUE, &hKey))
{
return lcid;
}
}
DWORD dwType;
DWORD dwcbData;
DWORD dwVal;
dwcbData = sizeof(dwVal);
LSTATUS lStatus = RegQueryValueEx(hKey, _T("language"), NULL, &dwType, (LPBYTE)&dwVal, &dwcbData);
if (ERROR_SUCCESS == lStatus)
{
lcid = (LCID)dwVal;
}
RegCloseKey(hKey);
return lcid;
}
void UpdateLanguage()
{
OSVERSIONINFO osvi;
BOOL bIsVistaOrLater;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
bIsVistaOrLater = (osvi.dwMajorVersion > 5);
LCID lcid = GetDefaultLCID();
//SetThreadUILanguage(MAKELANGID(LANG_DANISH, SUBLANG_DANISH_DENMARK));
// English:1033, French:1036, Italian: 1040, German: 1031
// Spanish: 1034, Danish: 1030, Dutch: 1043, Norwegian: 1044
// Swedish: 1053
if (bIsVistaOrLater)
{
SetThreadUILanguage(LANGIDFROMLCID(lcid));
}
else
{
SetThreadLocale(lcid);
}
}