Windows 10 detect keyboard layout change - c++

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?

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.

Related

Automatically filling a form and running a program

A friend sent me 3 programs, which are written in C or C++. Every program has a form, which is filled and then a button is pressed to perform some calculation. The programs were written in LabWindows/CVI which I've never heard of. He asked me, if it was possible to automatically fill the forms and run the calculation to get the output. I said that one way would be, to modify the program to a console one and run it with parameters (if the number of fields is low).
Does there exist a tool, which could be used to automate the execution of such programs or, if possible, does the LabWindows/CVI have anything which could help me, besides modifying the source?
I thank you in advance for you help.
you could use some automated test programs such as http://www.sikuli.org (this is written in java), it is also nice because you can add any java code you want to improve the test and modify it if you really need something extraordinary.
another way would be creating your own "automated test program" using c++ (since you posted this with c++ tag) to create a mouse and keyboard hook that will move the mouse and type characters on your forms.
the following links might help if you want to create your hooks C++ mouse click on certain spot in window, Global keyboard hook with WH_KEYBOARD_LL and keybd_event (windows)

Block alt+shift event or disable changing language in programming way

I need to block alt+shift keys event using C++, or some way to block changing language.
Thanks in advance.
I would go about it a bit differently. I would catch current langauge settings at startup than change it for desired one.
At the even of alt+shift i would just set it back to the desired type again.
It should be fairy easy to do with net framework.
Here is a short article about manipulating languages: How to change input language programmatically
And main class on msdna: InputLanguage documentation
To actually prevent alt+shift from moving into windows system you would have to play with hooks.
Here is an article about blocking keystrokes before windows process them.
Just an idea. You can catch WM_KEYDOWN message and call ActivateKeyboardLayout to switch language.
Using C++ you can install a keyboard hook procedure like the one suggested here and filter (swallow/don't propagate) the key(s) you want to forbid.
My understanding of MSDN is that you can pretend to process WM_INPUTLANGCHANGEREQUEST and then do nothing, so that Windows will not do anything further and the language will not actually change. But some users say that doesn't work any more.
http://msdn.microsoft.com/en-us/library/ms632630(VS.85).aspx
Maybe you can implement ITfInputProcessorProfileActivationSink::OnActivated, and when you get called you can change back to the previous language by calling ITfInputProcessorProfiles::ActivateLanguageProfile. At the beginning of your app you would call ITfInputProcessorProfiles::GetActiveLanguageProfile.
Maybe you can implement ITfLanguageProfileNotifySink::OnLanguageChange, set *pfAccept
to FALSE and return S_OK.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms628770(v=vs.85).aspx
All of the above have a problem. If the user intentionally changes languages on the client, for example by clicking on the client's task bar instead of pressing Alt+Shift, the above methods will prevent their change anyway.
I wonder if RegisterHotKey would let you register Alt+Shift for your own window even though the system already had it defined.
The thing you are trying to implement is keyboard hook. The detailed explanation with source code in C/C++ can be found here:
http://www.codeproject.com/Articles/67091/Mouse-and-KeyBoard-Hooking-utility-with-VC
Also other helpful examples can be found here:
http://www.codeproject.com/Articles/1264/KeyBoard-Hooks
http://www.codeproject.com/Articles/9513/Disable-keyboard-and-show-images-for-the-children
Hope this helps.
Kind regards,
Bo

Parse information from programs added to taskbar with C++

Basically what I am trying to do is write my own pseudo task bar in C++. The program needs to idle until another program is started up, at which point it needs to visually depict that the other program is running. For each other program that is running, the user should be able to click on the visual representation and have Windows switch focus to the selected program.
The big underlying question at this point: is this even a possibility? Or has Windows hidden most/all of its fiddly-bits to make this close to, if not completely, impossible?
[EDIT:] restructured the question
The obvious starting point would be SetWindowsHookEx(WH_SHELL,...); which will get you notifications when top-level windows are created or destroyed (along with some other related events, like a different window being activated, a window's title changing, etc.)
Think ahead to actually bringing the window to the front, as I once researched myself.
SetForegroundWindow() won't work unless issued from the foreground process - neither SwitchToThisWindow() nor the AttachThreadInput() kludge seemed to always work, but maybe I just wasn't doing it right. Anyway as far as I know there no way to make a window foreground as good as Windows does, please enlighten me if say you discover say an undocumented call which actually Works.
It seems possible to me at least in a basic way:
1. Set up a shell hook as described by Jerry
2. figure the executable file from the module handle to access it's icons using shell services
The Vista-like feature of keeping a 'live' miniature of the screen seems much more challenging.

How to launch an external application on BN_CLICKED?

I'm fairly new to Windows programming. I'm doing a simple launcher app for WinCE using VC++ (not MFC). So far I've created the basic interface and buttons and stuff. I just wanted to know the best way to launch an external application when the user clicks the button (on BN_CLICKED).
I found some methods such as ShellExecute, CreateProcess and others. But I couldn't get it to work (yet?). Any suitable reference or simple example on this?
The question don't matter that it happens inside the event of a button click, but...
ShellExecute is a good way to start programs (and the default program for any other type of files) in Windows, but use CreateProcess if you need a return code, or if you need the ability to wait for the program to finish.
Nevermind. I found a working example on MSDN - a comment by a user.
For anyone interested, you can go to this CreateProcess() article and scroll down to a comment entitled "Working code for creating two processes "p1.exe" and "p2.exe" using CreateProcess() Method"
Thanks!

A terminal-like window for wxWidgets?

I'm looking to add an element to my wxWidgets GUI that behaves like a terminal emulator. Not in terms of a shell which executes commands, but just the input-output setup of an application running in a terminal.
Basically, the requirements are:
Streaming input/output: When you enter a character, it is added to an input stream, and when something is piped to the terminal, it prints out immediately.
No editing: Once you type in a character, it's permanently there, since it's probably been consumed by the application running in the terminal.
Some sort of scrolling (even if it just shows a few lines or something).
It would be nice if there is something that already does this, but suggestions on how to implement this with already existing controls such as wxTextCtrl would also be welcome.
I know this is a couple weeks late, but hopefully it's still useful. I've got a project called Chameleon that uses a wxWidgets-based VT100 terminal widget, which was itself based off of a project called taTelnet. The Chameleon source is available from my website (download page here). Not sure if it's exactly what you're looking for, but it might give you some ideas. Feel free to let me know if you have any questions about it.
wxWidgets supports redirecting STDOUT to a wxTextCtrl via wxStreamToTextRedirector. As for input, you could override the OnChar event in a wxTextCtrl-derived class to handle this.