emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: National Language Support Functions


From: Eli Zaretskii
Subject: Re: National Language Support Functions
Date: Fri, 22 Dec 2006 14:14:42 +0200

> Date: Fri, 22 Dec 2006 01:11:01 +0100
> From: Lennart Borgman <address@hidden>
> CC:  address@hidden

Could people who have access to MS-Windows please try these two
programs and report the results?  It is important to describe the full
details about your regional and international settings (found in
Control Panel) on each machine where you test this.

Thanks in advance.

> Eli Zaretskii wrote:
> > On my system, it returns Hebrew as the system default, and US English
> > as the user default, which is exactly how I configured this system.
> > So Emacs does the right thing for me.
> >
> > #include <windows.h>
> > #include <stdio.h>
> >
> > int main (void)
> > {
> >   LANGID lsys = GetSystemDefaultLangID ();
> >   LANGID lusr = GetUserDefaultLangID ();
> >
> >   printf ("SYS: 0x%x, USR: 0x%x\n", lsys, lusr);
> >
> >   return 0;
> > }
> >   
> 
> I think the tests above are not the correct tests for the UI language.
> 
> I searched a bit to find out again how to test this. It turns out to be 
> a bit complicated if one wants to support different versions of Windows. 
> I suggest that we only support later versions and then use 
> GetUserDefaultUILanguage and dito System variant. Here is some code to test:
> 
> #include <windows.h>
> #include <winnls.h>
> #include <windef.h>
> #include <tchar.h>
> #include <stdio.h>
> 
> #define TRACE(s, l)    (fprintf(stdout, s, l))
> 
> int main (void)
> {
>   LANGID lsys = GetSystemDefaultLangID ();
>   LANGID lusr = GetUserDefaultLangID ();
> 
>   printf ("LangID = SYS: 0x%x, USR: 0x%x\n", lsys, lusr);
> 
>   LCID lcidsys = GetSystemDefaultLCID ();
>   LCID lcidusr = GetUserDefaultLCID ();
> 
>   printf ("LCID = SYS: 0x%x, USR: 0x%x\n", lcidsys, lcidusr);
> 
>   //WINBASEAPI LANGID WINAPI GetSystemDefaultUILanguage(void);
>   //WINBASEAPI LANGID WINAPI GetUserDefaultUILanguage(void);
>   //LANGID luisys = GetSystemDefaultUILanguage();
>   //LANGID luiusr = GetUserDefaultUILanguage ();
> 
>   //printf ("UILang = SYS: 0x%x, USR: 0x%x\n", luisys, luiusr);
> 
>   {
>     LANGID langid = 0;
>     int nPrimaryLang = 0;
>     int nSubLang = 0;
>     LCID lcid = 0;
>     typedef LANGID (WINAPI * PFNGETUSERDEFAULTUILANGUAGE)
>       (
>        void);
>     PFNGETUSERDEFAULTUILANGUAGE pfnGetUserDefaultUILanguage;
>     typedef LANGID (WINAPI * PFNGETSYSTEMDEFAULTUILANGUAGE)
>       (
>        void);
>     PFNGETSYSTEMDEFAULTUILANGUAGE pfnGetSystemDefaultUILanguage;
>     HINSTANCE hKernel32;
> 
>     hKernel32 = GetModuleHandle(_T("kernel32.dll"));
>     pfnGetUserDefaultUILanguage =
>       
> (PFNGETUSERDEFAULTUILANGUAGE)GetProcAddress(hKernel32,"GetUserDefaultUILanguage");
>     if(pfnGetUserDefaultUILanguage != NULL)
>       {
>         langid = pfnGetUserDefaultUILanguage();
>         TRACE(_T("GetUserDefaultUILanguage() = %04X\n"), langid );
> 
>         pfnGetSystemDefaultUILanguage =
>           
> (PFNGETSYSTEMDEFAULTUILANGUAGE)GetProcAddress(hKernel32,"GetSystemDefaultUILanguage");
>         //ASSERT( pfnGetSystemDefaultUILanguage != NULL );
> 
>         langid = pfnGetSystemDefaultUILanguage();
>         TRACE(_T("GetSystemDefaultUILanguage = %04X\n"), langid );
>       }
>     else
>       {
>         // We're not on an MUI-capable system.
>         if (GetVersion()&0x80000000)
>           {
>             // We're on Windows 9x, so look
>             // in the registry for the UI language
>             HKEY hKey = NULL;
>             LONG nResult = RegOpenKeyEx(HKEY_CURRENT_USER,
>                                         _T( "Control 
> Panel\\Desktop\\ResourceLocale" ),
>                                         0, KEY_READ, &hKey);
>             if (nResult == ERROR_SUCCESS)
>               {
>                 DWORD dwType;
>                 TCHAR szValue[16];
>                 ULONG nBytes = sizeof( szValue );
>                 nResult = RegQueryValueEx(hKey, NULL, NULL, &dwType,
>                                           (LPBYTE) szValue, &nBytes );
>                 if ((nResult == ERROR_SUCCESS) && (dwType == REG_SZ))
>                   {
>                     DWORD dwLangID;
>                     int nFields = _stscanf( szValue, _T( "%x" ), &dwLangID );
>                     if( nFields == 1 )
>                       {
>                         langid = (LANGID) dwLangID;
>                         TRACE(_T("Win 9x registry language = %04X\n"), langid 
> );
>                       }
>                   }
>                 RegCloseKey(hKey);
>               }
>           }
>         else
>           {
>             // We're on NT 4. The UI language
>             // is the same as the language of the
>             // version resource in ntdll.dll
> /*             HMODULE hNTDLL = GetModuleHandle( _T( "ntdll.dll" ) ); */
> /*             if (hNTDLL != NULL) */
> /*               { */
> /*                 langid = 0; */
> /*                 EnumResourceLanguages( hNTDLL, RT_VERSION, 
> MAKEINTRESOURCE( 1 ), */
> /*                                        _AfxEnumResLangProc, */
> /*                                        reinterpret_cast< LONG_PTR >( 
> &langid ) ); */
> /*                 if (langid != 0) */
> /*                   { */
> /*                     AddLangId( langid ); */
> /*                     TRACE(_T("CMultiLanguage::DetectUILanguage() NT1st/2nd 
> = %04X\n"), langid ); */
> /*                   } */
> /*               } */
>           }
>       }
> 
> 
>   }
>   return 0;
> }
> 
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]