I'm trying to implement a service that would monitor language/layout changes. I switch between English and Russian languages. So far I've found this question and tried to implement and install both sinks suggested there.
However, there are problems. ITfActiveLanguageProfileNotifySink::OnActivated
is not triggered at all; ITfLanguageProfileNotifySink::OnLanguageChange
is not triggered, too; ITfLanguageProfileNotifySink::OnLanguageChanged
is triggered only when the main window of my program is in foreground, but it doesn't contain any information on the language. Is there any way to monitor input language change event globally?
Asked
Active
Viewed 625 times
2

Andrew Sokolov
- 277
- 2
- 12
-
Does your app main window get the [`WM_INPUTLANGCHANGE` message](https://learn.microsoft.com/en-us/windows/win32/winmsg/wm-inputlangchange)? – Adrian Mole Feb 03 '22 at 23:57
-
@AdrianMole no, unfortunately it doesn't. I think it might be because I have an edit box that fills the whole window and the message is sent to it instead of the main frame. Anyway, the message should be sent to the active window only, and I need to be able to react to input language changes even when my window is in the background. – Andrew Sokolov Feb 04 '22 at 08:24
-
OnActivated should we called, shouldn't it? Do you have any reproducing project? – Simon Mourier Feb 11 '22 at 07:04
-
@SimonMourier yes, here's the default VS2019 "desktop app" [project](https://github.com/sokolas/lang_change) with `ITfActiveLanguageProfileNotifySink` implementation that I took from [this example](https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/IME/cpp/SampleIME/ActiveLanguageProfileNotifySink.cpp) – Andrew Sokolov Feb 11 '22 at 11:03
-
I don't think this interface is for a Windows global language change, more for your application only, if that's what you're after – Simon Mourier Feb 11 '22 at 11:48
1 Answers
2
I found another way to detect such changes: to use SetWindowsHookEx with WH_SHELL
. One of the available event is HSHELL_LANGUAGE
which is exactly what I need and the test project seems to work just fine.
There's an article by Alexander Shestakov that describes a program very similar to what I'm trying to achieve and it also has a link to github project that I use as an example.

Andrew Sokolov
- 277
- 2
- 12