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");
}
The traditional way of doing this was to handle the WM_INPUTLANGCHANGE
message. But there are a couple of problems with this method:
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.
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.
You can use WM_INPUTLANGCHANGE
message:
case WM_INPUTLANGCHANGE:
{
HKL hkl = (HKL)lParam;
WCHAR localeName[LOCALE_NAME_MAX_LENGTH];
LCIDToLocaleName(MAKELCID(LOWORD(hkl), SORT_DEFAULT), localeName, LOCALE_NAME_MAX_LENGTH, 0);
WCHAR lang[9];
GetLocaleInfoEx(localeName, LOCALE_SISO639LANGNAME2, lang, 9);
}
https://docs.microsoft.com/windows/win32/intl/locale-names https://docs.microsoft.com/windows/win32/intl/nls--name-based-apis-sample
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With