代码之家  ›  专栏  ›  技术社区  ›  Abhishek nazim hatipoglu

获取Windows 10中已安装语言的列表

  •  0
  • Abhishek nazim hatipoglu  · 技术社区  · 7 年前

    我需要在列表中显示已安装语言的列表 ComboBox 在一个 WPF 组合框

    CultureInfo 这门课。下面是我正在尝试的一个片段。我能得到所有的文化。但我只需要那些通过系统设置安装的区域性。

    var cultureInfos = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
    foreach (var culture in cultureInfos)
    {
        Console.WriteLine(culture.Name);
    }
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   dymanoid    7 年前

    您可以使用本机函数 GetKeyboardLayoutList 获取已安装输入语言的列表。

    IEnumerable<CultureInfo> GetInstalledInputLanguages()
    {
        // first determine the number of installed languages
        uint size = GetKeyboardLayoutList(0, null);
        IntPtr[] ids = new IntPtr[size];
    
        // then get the handles list of those languages
        GetKeyboardLayoutList(ids.Length, ids);
    
        foreach (int id in ids) // note the explicit cast IntPtr -> int
        {
            yield return new CultureInfo(id & 0xFFFF);
        }
    }
    
    [DllImport("user32.dll")]
    static extern uint GetKeyboardLayoutList(int nBuff, [Out] IntPtr [] lpList);