title author date CreateTime categories
WPF 获得当前输入法语言区域
lindexi
2019-06-23 11:51:21 +0800
2018-10-12 11:5:41 +0800
WPF

本文告诉大家如何获得 WPF 输入法的语言区域

需要使用 user32 的方法,很简单,请看下面

       [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hwnd, IntPtr proccess);
[DllImport("user32.dll")] static extern IntPtr GetKeyboardLayout(uint thread); public CultureInfo GetCurrentKeyboardLayout()
{
try
{
IntPtr foregroundWindow = GetForegroundWindow();
uint foregroundProcess = GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero);
int keyboardLayout = GetKeyboardLayout(foregroundProcess).ToInt32() & 0xFFFF;
return new CultureInfo(keyboardLayout);
}
catch (Exception)
{
return new CultureInfo(1033); // Assume English if something went wrong.
}
}

因为没有提供语言区域变化的事件,所以需要自己写一个循环来获取

在界面添加一个 TextBlock 请看下面

    <Grid>
<TextBlock x:Name="CeareamearTreseretal" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>

这样可以在后台代码给一个值

        private async void HairjurNalllairmo()
{
while (true)
{
await Task.Delay(100);
CeareamearTreseretal.Text = GetCurrentKeyboardLayout().DisplayName;
}
}

这时修改语言区域就可以看到变化

参见 C#: Get current keyboard layout\input language

2019-6-23-WPF-获得当前输入法语言区域的更多相关文章

  1. WPF 获得当前输入法语言区域

    原文:WPF 获得当前输入法语言区域 本文告诉大家如何获得 WPF 输入法的语言区域 需要使用 user32 的方法,很简单,请看下面 [DllImport("user32.dll" ...

  2. Android默认输入法语言的修改以及SettingsProvider作用

    Android源码中默认的有三种输入法:英文,中文,日文.对应的工程代码路径为:<android_root>/packages/inputmethods/LatinIME/<andr ...

  3. Beta冲刺(2/7)——2019.5.23

    所属课程 软件工程1916|W(福州大学) 作业要求 Beta冲刺(2/7)--2019.5.23 团队名称 待就业六人组 1.团队信息 团队名称:待就业六人组 团队描述:同舟共济扬帆起,乘风破浪万里 ...

  4. WPF 实际国际化多语言界面

    前段时候写了一个WPF多语言界面处理,个人感觉还行,分享给大家.使用合并字典,静态绑定,动态绑定.样式等东西 效果图 定义一个实体类LanguageModel,实际INotifyPropertyCha ...

  5. 跟我一起学WPF(1):WPF的UI设计语言——XAML

    XAML是什么 XAML全称是Extensible Application Markup Language (可扩展应用程序标记语言),是专门用于WPF技术中的UI设计语言. XAML基础 XAML是 ...

  6. WPF 本地化(多语言)

    如果你的程序需要本地化,考虑的因素诸多,例如:当文本改变后,控件的当前高度,宽度 是否合适.所在的位置是否合适.字体.布局是否合适?如果已经构建了一个真正自适应的布局,就不会有问题.用户界面应当能够调 ...

  7. 让你提前认识软件开发(23):怎样在C语言中运行shell命令?

    第1部分 又一次认识C语言 怎样在C语言中运行shell命令? [文章摘要] Linux操作系统具备开源等诸多优秀特性,因此在很多通信类软件(主流开发语言为C语言)中,开发平台都迁移到了Linux上, ...

  8. 2017.12.23 第二章 统一建模语言UML概述

    第二章 统一建模语言UML概述 (1)为什么要建模 模型是某个事物的抽象,其目的是在构建这个事物之前先来理解它,因为模型忽略了那些非本质的细节,这样有利于更好的理解和表示事物: 在软件系统开发之前首先 ...

  9. 2019.9.30极限测试 04.JAVA语言课堂测试试卷-极限测试

    题目存储在上传的文件当中. 代码实现 Subway 类: package ClassroomTest; public class Subway { private String railway; pr ...

随机推荐

  1. leetcode 492-543 easy

    492. Construct the Rectangle Input: 4 Output: [2, 2] Explanation: The target area is 4, and all the ...

  2. css3正方体效果

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. angular可以做的小功能 未完成

    1,网上购物满多少减多少 思路: 效果图,满500减10元邮费 1,html部分有基本布局, <div> <h3>化妆品</h3> 单价 <input typ ...

  4. iOS 动画队列—仿映客刷礼物效果

    http://www.cocoachina.com/ios/20160719/17101.html 最近在研究直播的相关知识,在网上看到了不少优秀的开源项目,但都没有看到映客那个刷礼物的效果,于是手痒 ...

  5. python中星号

    第一种情况:用在两表达式的中间,*表示乘法,**表示取幂,如: 1 2 3 4 >>> 2*5 10 >>> 2**7 128 第二种情况:用在变量的前面. 1,向 ...

  6. 交互题(apio2016Gap)

    题目链接   //Serene #include<algorithm> #include<iostream> #include<cstring> #include& ...

  7. 解决安装编译工具gcc后无法连接mysql

    在安装编译工具gcc后: yum -y install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2 ...

  8. Hdu 4251 区间中位数(划分树)

    题目链接 The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  9. CSS 连接后面加上"?"表示什么意思?

    举例来说: <link rel="stylesheet" href="http://static.ak.facebook.com/css/actionspro.cs ...

  10. django1.11启动错误

    错误信息: 复制代码 Unhandled exception in thread started by <function check_errors..wrapper at 0x10f03b8c ...