简体   繁体   中英

Change the language of the native 'Pick Icon' dialog window?

In the (open-source) application of the screenshot below, I'm calling the PickIconDlg function to display a dialog window to view and select a icon:

I just would like to know if exists the possibility to change the language in which that dialog window is shown for the current running process.

I checked that SetProcessPreferredUILanguages works fine for changing the language of common file and folder dialogs, but it does not affect the 'Pick Icon' dialog.

I am able to change language the 'Pick Icon' dialog, with the simple code below:

#include <windows.h>
#include <Shlobj.h>
#pragma comment(lib, "Shell32.lib")
int main(void)
{
    ULONG n;
    WCHAR s[] = L"C:\\Windows\\Explorer.exe"; 
    int i = 1;
    n = 1;
    WCHAR langs[] = L"zh-CN\0";
    BOOL ret = SetProcessPreferredUILanguages(MUI_LANGUAGE_NAME, langs, &n);
    PickIconDlg(NULL,s, wcslen(s)+1,&i);
}

Result:(Note that the default language on My environment is "en-US") 在此处输入图片说明

Seems that you need to install the Language package first. Settings > Time&Language > Language > Add a preferred language, then select the language you've added and go into Options, install the Language package.

C# version :

public enum MUIFlags : uint
{
    MUI_LANGUAGE_ID = 0x4,
    MUI_LANGUAGE_NAME = 0x8,
}

[SuppressUnmanagedCodeSecurity, SecurityCritical]
internal static class NativeMethods
{
    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
    internal static extern bool SetProcessPreferredUILanguages(MUIFlags dwFlags, 
        string pwszLanguagesBuffer, ref uint pulNumLanguages);

    [DllImport("Shell32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    internal static extern int PickIconDlg(IntPtr hwnd, string pszIconPath, 
        uint cchIconPath, ref int piIconIndex);
}

The languages can be set as an array of ISO names:
(The first language available in the System, in the order provided, will be used as the Dialog language).

string[] languages = new[] { "de-DE", "en-US", "it-IT", "es-ES", "fr-FR" };

Or using the Thread.CurrentThread.CurrentCulture (or CurrentUICulture ):

string[] languages = new[] { Thread.CurrentThread.CurrentUICulture.Name };

Or using a specific culture (using CultureInfo.CreateSpecificCulture() ):

string[] languages = new[] { CultureInfo.CreateSpecificCulture("en-US").Name };

uint numLangs = 0;
string langs = string.Join("\u0000", languages);
bool result = NativeMethods.SetProcessPreferredUILanguages(MUIFlags.MUI_LANGUAGE_NAME, 
    languages, ref numLangs);

string iconsPath = Path.Combine(Environment.SystemDirectory, "shell32.dll");
int selIcon = -1;
if (PickIconDlg(IntPtr.Zero, iconsPath, (uint)iconsPath.Length, ref selIcon) > 0)
{
    // selIcon is set to the selected Icon's index
}

VB.Net version :

Public Enum MUIFlags As UInteger
    MUI_LANGUAGE_ID = &H4
    MUI_LANGUAGE_NAME = &H8
End Enum

<SuppressUnmanagedCodeSecurity, SecurityCritical>
Friend Class NativeMethods
    <DllImport("Kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
    Friend Shared Function SetProcessPreferredUILanguages(dwFlags As MUIFlags,
        pwszLanguagesBuffer As String, ByRef pulNumLanguages As UInteger) As Boolean
    End Function

    <DllImport("Shell32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Friend Shared Function PickIconDlg(hwnd As IntPtr, pszIconPath As String, cchIconPath As UInteger, ByRef piIconIndex As Integer) As Integer
    End Function
End Class

Dim languages As String() = {"es-ES", "fr-FR", "en-US"}
Dim langs As String = String.Join(vbNullChar, langNames)

Dim numLangs As UInteger = 0
Dim result As Boolean = NativeMethods.SetProcessPreferredUILanguages(MUIFlags.MUI_LANGUAGE_NAME, 
    langs, numLangs)

Dim iconsPath As String = Path.Combine(Environment.SystemDirectory, "shell32.dll")
Dim selIcon As Integer = -1
If PickIconDlg(IntPtr.Zero, iconsPath, CUInt(iconsPath.Length), selIcon) > 0 Then
    ' selIcon is set to the selected Icon's index
End If

A full implementation of SetProcessPreferredUILanguages , GetProcessPreferredUILanguages , including declarations and wrapper methods, is available here:

Can't read all the language names returned by GetProcessPreferredUILanguages function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM