当用户在 Windows 中更改语言键盘布局时如何得到通知? [英] How to be informed when user changes the language keyboard layout in Windows?

查看:29
本文介绍了当用户在 Windows 中更改语言键盘布局时如何得到通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户更改Windows 的语言键盘布局(例如从EN 更改为FR)时,我想向用户显示一条消息.但我不知道当用户使用任务栏或 ALT+SHIFT 更改它时如何通知我.我应该使用哪个 win32api 函数?我需要这样的伪代码:

I want to show a message to user when the user changes the language keyboard layout of Windows for example from EN to FR. But I don't know how can I be informed when the user changes it using either the taskbar or ALT+SHIFT. Which win32api function should I use? I need something like this pseudocode :

void inputLanguageChanged(char *ln)
{
  message("You selected " + ln + " language");
}

推荐答案

传统的做法是处理 WM_INPUTLANGCHANGE 消息.但是这种方法有几个问题:

The traditional way of doing this was to handle the WM_INPUTLANGCHANGE message. But there are a couple of problems with this method:

更好的解决方案是实施 ITfLanguageProfileNotifySink 接口,其 OnLanguageChanged 方法 每当输入语言发生变化时都会被调用,而不管它的变化方式如何.

The better solution, then, is to implement the ITfLanguageProfileNotifySink interface, whose OnLanguageChanged method is called whenever the input language changes, regardless of the way that it was changed.

但是,我看到您的问题同时带有 C 和 C++ 标签.您可以从 C 中使用 COM,但这真的很伤人.如果您使用 C++,则简单得多.如果我需要在 C 程序中完成这项工作,我可能只是想办法让 WM_INPUTLANGCHANGE 为我工作.也许我只是懒惰.

However, I see that your question is tagged with both the C and C++ tags. You can use COM from C, but it's a real pain in the neck. Far simpler if you're using C++. If I needed to do this work in a C program, I'd probably just find a way to make WM_INPUTLANGCHANGE work for me. Maybe I'm just lazy.

这篇关于当用户在 Windows 中更改语言键盘布局时如何得到通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆