It is currently Wed Sep 18, 2019 7:07 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Detecting the active display language in windows 7 upwards
PostPosted: Mon Apr 15, 2019 5:09 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Apr 10, 2017 6:17 pm
Posts: 263
Location: Germany
Hi,

i am trying to correctly and reliably detect the currently used display language of a windows installation. It is simple to do by scanning the output, but i have'nt found a working reliable API way so far.

For exaple my main machine is using an english windows7 ultimate installation which has the german language pack installed as optional display language pack. If i call system commands on the commandline like "diskpart", the output differs depending on the display language i select.

The topic has been brought up on other forums including slashdot and there seems to be an easy solution by api calls like GetSystemDefaultLangID_() or GetUserDefaultLangID_() but none of them works reliably in windows 7 and windows 10 for me.

Does anybody know a reliable win32 API way to do it?

MSI maybe? It should have the answer, but where?

Thanks in advance!

_________________
webpage


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 6:01 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3395
Tested with Windows 10
Code:
kbd$ = Space(12)
OpenWindow(0,0,0,100,100,"test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,0,0,0,0,"") ;Dummy Gadget
ButtonGadget(1,10,60,120,20,"Get Active Language")
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
    Case #PB_Event_Gadget
      Select EventGadget()       
        Case 0
          Select EventType()
            Case #PB_EventType_Focus
              GetKeyboardLayoutName_(@kbd$)
              Debug kbd$
          EndSelect
         
        Case 1
          SetFocus_(GadgetID(0))
      EndSelect
  EndSelect
Until Quit = 1
End


Code:
kbd$ = Space(12)
OpenWindow(0,0,0,120,24,"test", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
StringGadget(0,0,0,0,0,"") ;Dummy Gadget
ButtonGadget(1,0,0,120,24,"Get Active Language")
Repeat
  Select WaitWindowEvent()
    Case #WM_CHAR
      Quit = EventwParam()
     
    Case #PB_Event_Gadget
      Select EventGadget()       
        Case 0
          Select EventType()
            Case #PB_EventType_Focus
              GetKeyboardLayoutName_(@kbd$)
              SetActiveGadget(-1)
              MessageRequester("Info","Active Keboard : "+kbd$,#MB_OK|#MB_ICONINFORMATION)             
          EndSelect
         
        Case 1
          SetFocus_(GadgetID(0))
      EndSelect
  EndSelect
Until Quit = 27
End

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 7:04 pm 
Online
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 461
Rashad , thank you for your Codes above , as i needed that also !

much more additional info in these 2 Links :

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-input-locales-for-windows-language-packs

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/available-language-packs-for-windows

_________________
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 7:48 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Apr 10, 2017 6:17 pm
Posts: 263
Location: Germany
Thanks Rashad, but thats always 0407 (keyboard language name - just like MSI win32_operatingsystem\locale). What i need is the display language setting instead.

_________________
webpage


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 8:14 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3395
Check the Registry for
Windows 10 :
HKCU\Control Panel\Desktop\MuiCached

For other Windows versions
HKCU\Control Panel\Desktop\MultiUILanguageId

Code:
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\MuiCached"
sValueName.s = "MachinePreferredUILanguages"

Procedure.l QueryValueEx(lhkey.l, szValueName.s)
    Shared vValue.s
    cch = 255
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)       
    Select lType
        Case #REG_MULTI_SZ
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
            If lrc = 0
                vValue.s = Left(sValue.s, cch-1)
            Else
                vValue.s = "Empty"
            EndIf
        Default
            lrc = -1
    EndSelect
    ProcedureReturn lrc
EndProcedure

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  Debug vValue.s
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 8:47 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Apr 10, 2017 6:17 pm
Posts: 263
Location: Germany
Thanks but same problem - it reports en-us while the german language is active (de-de i guess) in win7.

Maybe its just a win7 problem?
\
ps: a registry search and 3 tests did seem to point at hkey_currentuser\control panel\Desktop\MuiCached\MachinePreferedUILanguages in win7

_________________
webpage


Last edited by Bitblazer on Mon Apr 15, 2019 9:11 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Mon Apr 15, 2019 9:02 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3395
When you start your OS
What is the Active display language ?

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Tue Apr 16, 2019 5:36 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Apr 10, 2017 6:17 pm
Posts: 263
Location: Germany
This works with win7 even if you switch the language after boot. Thanks Rashad.

Code:
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"

Procedure.l QueryValueEx(lhkey.l, szValueName.s)
    Shared vValue.s
    cch = 255
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)       
    Select lType
        Case #REG_MULTI_SZ
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
            If lrc = 0
                vValue.s = Left(sValue.s, cch-1)
            Else
                vValue.s = "Empty"
            EndIf
        Default
            lrc = -1
    EndSelect
    ProcedureReturn lrc
EndProcedure

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  Debug vValue.s
EndIf

_________________
webpage


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Thu Apr 18, 2019 5:38 am 
Offline
Enthusiast
Enthusiast

Joined: Mon May 10, 2010 4:02 pm
Posts: 149
There is no such key in my system (win 7x64)
Quote:
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"

This code works:
Code:
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\International"
sValueName.s ="LocaleName" ;  or "sLanguage"  ; or "sCountry"

Procedure.l QueryValueEx(lhkey.l, szValueName.s)
    Shared vValue.s
    cch = 255
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)       
    Select lType
        Case #REG_SZ
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
            If lrc = 0
                vValue.s = Left(sValue.s, cch-1)
            Else
                vValue.s = "Empty"
            EndIf
        Default
            lrc = -1
    EndSelect
    ProcedureReturn lrc
EndProcedure

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  Debug vValue.s
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting the active display language in windows 7 upwar
PostPosted: Thu Apr 18, 2019 11:56 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Apr 10, 2017 6:17 pm
Posts: 263
Location: Germany
kvitaliy wrote:
There is no such key in my system (win 7x64)
Quote:
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"

This code works:
Code:
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\International"
sValueName.s ="LocaleName" ;  or "sLanguage"  ; or "sCountry"

Procedure.l QueryValueEx(lhkey.l, szValueName.s)
    Shared vValue.s
    cch = 255
    sValue.s = Space(255)
    lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)       
    Select lType
        Case #REG_SZ
            lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
            If lrc = 0
                vValue.s = Left(sValue.s, cch-1)
            Else
                vValue.s = "Empty"
            EndIf
        Default
            lrc = -1
    EndSelect
    ProcedureReturn lrc
EndProcedure

lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)

If lRetVal = 0
  Debug vValue.s
EndIf


beware - on my english win7 ultimate installation with two installed display languages (german and english), the following keys all point to german

Code:
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\International"
sValueName.s ="LocaleName" ;  or "sLanguage"  ; or "sCountry"


while
Code:
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\MuiCached"
sValueName.s ="MachinePreferredUIlanguages"

correctly points to the currently active display language.

So i guess we should use that key and only if it doesnt exist, use the others as fallback option. Thats what im going to do now (and probably evaluate it by calling an OS tool and check which language the tool actually uses ;). What a mess :o

_________________
webpage


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye