Re: SDK integration in VS2005
Hi Hans-J?rgen,
* Hans-J. Ude <news@hajue-ude.de> wrote:
So I tried to use SetThreadUILanguage() instead. Now comes the
problem. That function is undefined.
I choosed another way, see below. Unfortunately SetThreadLocale does not
always work. On one computer it works for me for one user, but not for
another user. MSDN says that it is not recommended, one should use other
ways like FindResourceEx (a lot of changes), or satellite language dlls.
///////////////////////////////////////////////////////////////////////
// \author Christoph Conrad
// \date 05.11.2007
// \note Check if OS is vista or newer
// \return true if OS is vista or newer
///////////////////////////////////////////////////////////////////////
bool IsVistaOrNewer()
{
OSVERSIONINFO OSversion;
OSversion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&OSversion);
// check for vista or newer
return OSversion.dwMajorVersion >= 6;
}
///////////////////////////////////////////////////////////////////////
// \author Christoph Conrad
// \date 05.11.2007
// \note Switch program language
// \param the language identifier, e.g. LANG_GERMAN ("winnt.h")
// \return true if switching worked
///////////////////////////////////////////////////////////////////////
bool SwitchLanguage(USHORT primaryLanguage)
{
LANGID langId = MAKELANGID(primaryLanguage, SUBLANG_DEFAULT);
bool success = false;
// check for vista or newer
// In Windows XP SetThreadUILanguage() also exists, but the parameter is
// ignored. So we must check if it is vista.
if( IsVistaOrNewer() )
{
// Hole Handle fuer die DLL.
HMODULE dllHandle = LoadLibrary("kernel32");
success = dllHandle != NULL;
// Wenn Handle gueltig, ermittle Adresse der Funktion.
if( success )
{
typedef short (CALLBACK* SetThreadUILanguageType)(LANGID);
SetThreadUILanguageType stuiPtr = (SetThreadUILanguageType)
GetProcAddress(dllHandle, "SetThreadUILanguage");
success = stuiPtr && stuiPtr(langId) != 0;
// Aufraeumen
FreeLibrary(dllHandle);
}
}
// fallback, try SetThreadLocale()
if( ! success )
{
success =
::SetThreadLocale( MAKELCID(langId, SORT_DEFAULT ) ) != 0;
}
return success;
}
Best regards,
Christoph