Results 1 to 4 of 4

Thread: SetThreadPreferredUILanguages not working as advertised.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    363

    SetThreadPreferredUILanguages not working as advertised.

    SetThreadPreferredUILanguages should change the language displayed in captions and buttons of shell dialogs in the current thread (in Windows Vista and later versions).

    In the code example below, the locale language is successfully changed to spanish, it also works for French and english BUT it doesn't work for ARABIC.

    sLang = "en-us" & Chr$(0) '<== English ....works
    sLang = "es-es" & Chr$(0) '<== Spanish ....works
    sLang = "fr-fr" & Chr$(0) '<== French ....works

    sLang = "ar-eg" & Chr$(0) '<== Arabic (Egypt) ....DOESN'T WORK


    Code:
    Option Explicit
    
    Declare Function SetThreadPreferredUILanguages Lib "kernel32" _
    (ByVal dwFlags As Long, ByVal PCZZWSTR As Long, ByRef PULONG As Long) As Long
    
    Declare Function SetProcessPreferredUILanguages Lib "kernel32" _
    (ByVal dwFlags As Long, ByVal PCZZWSTR As Long, ByRef PULONG As Long) As Long
    
    Declare Function PickIconDlg Lib "shell32" Alias "#62" ( _
            ByVal hwndOwner As Long, _
            ByVal szFilename As String, _
            ByVal Reserved As Long, _
            lpIconIndex As Long _
        ) As Long
    
    
    Sub Test()
        
        Const MUI_LANGUAGE_NAME = &H8
        Dim sLang As String, TmpIconFile As String * 256
    
        sLang = "es-es" & Chr$(0)
    
        Call SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, StrPtr(sLang), 0&)
        Call PickIconDlg(Application.hwnd, TmpIconFile, Len(TmpIconFile), 0)
    
    End Sub
    I have also tried using SetProcessPreferredUILanguages but still doesn't work.

    BTW, I am running the code in Windows 10 x64 and I have all above mentioned Language packs fully installed including the Arabic language pack.

    Do these APIs don't work with unicode languages ? Any Ideas ?

    Regards.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    363

    Re: SetThreadPreferredUILanguages not working as advertised.

    Anyone ?

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    2,312

    Re: SetThreadPreferredUILanguages not working as advertised.

    Use EnumUILanguages API w/ MUI_LANGUAGE_NAME flag to dump currently installed languages for UI.

    The name could be "ar-EG" instead of "ar-eg" or the language could be missing at all for some other reason.

    cheers,
    </wqw>

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2013
    Posts
    363

    Re: SetThreadPreferredUILanguages not working as advertised.

    Quote Originally Posted by wqweto View Post
    Use EnumUILanguages API w/ MUI_LANGUAGE_NAME flag to dump currently installed languages for UI.

    The name could be "ar-EG" instead of "ar-eg" or the language could be missing at all for some other reason.
    Thanks for the tip.

    Code:
    Declare Function SysReAllocString Lib "oleAut32.dll" _
        (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
    
    Declare Function EnumUILanguages Lib "kernel32.dll" _
                     Alias "EnumUILanguagesW" ( _
                     ByVal lpUILanguageEnumProc As Long, _
                     ByVal dwFlags As Long, _
                     ByRef lParam As Long) As Long
                     
    
    Const MUI_LANGUAGE_NAME = &H8
      
    Public Sub Test()
        EnumUILanguages AddressOf EnumLangsProc, MUI_LANGUAGE_NAME, 0&
    End Sub
    
    Private Function EnumLangsProc(ByVal Arg1 As Long, ByRef Arg2 As Long) As Long
        Debug.Print GetStrFromPtrW(Arg1)
        EnumLangsProc = 1
    End Function
    
    
    Private Function GetStrFromPtrW(ByVal Ptr As Long) As String
        SysReAllocString VarPtr(GetStrFromPtrW), Ptr
    End Function
    This is the output I got from the code above:

    fr-FR
    ar-SA <=== Passing this string to SetThreadPreferredUILanguages now works ok.
    en-GB
    en-US
    es-ES


    BUT the thing I don't understand is the fact that I don't have ar-SA (Arabic - Saudi Arabia) installed !!!!

    I only have ar-EG(Arabic - Egypt) and ar-MA (Arabic - Morocco) installed in my computer neither of which show up in the output dump !!!


    (See below image for my computer language preferences - Arabic - Saudi Arabia is not there on the Preferred Languages List!!)

    Name:  languages.jpg
Views: 33
Size:  22.0 KB
    Last edited by JAAFAR; Sep 26th, 2020 at 01:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width