How do I find out what state you're in?

by Michael S. Kaplan, published on 2011/05/19 07:01 -04:00, original URI:

Over in the Suggestion Box, John asked:

I'm trying to figure out how to get (and possibly change) the IME state of the active window, like the language bar does.  Assume for the moment that I only need to support TSF.  Is there a reasonable (a.k.a., will probably continue to work in the future) way to accomplish this?

The only thing I've been able to find in the TSF docs that seems potentially of interest is ITfLangBarMgr::GetThreadLangBarItemMgr.  I'm somewhat concerned that the only documentation MSDN provides for this function is "Should not be used."  I've tried calling it, but it only seems to work if I pass the thread ID of my own thread; otherwise I get "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)".  Can this function be made to work, is there a better way, or is there no good way to do this?

Now the Language Bar does its magic in what most reasonable people would consider to be an extreme way -- it puts itself in every thread (well, technically every threadgroup) so that it can make changes from any input thread, if need be.

Many "internal" Text Services Framework methods like ITfLangBarMgr::GetThreadLangBarItemMgr that work differently within one's own thread than outside of it -- because they are helper classes and methods designed to be used by that code that lives in every threadgroup to keep the central code behind the language bar up to date.

Others, such as this one, are actually not internal so much as meant to be used by actual text services like IMEs that need to do things to update the language bar based on their own state. thus it won't really work very well unless you can manage to be in each threadgroup that might need the information.

However, this does not mean there is no hope!

For starters there is IMM32 way (i.e. ImmGetConversionStatus and ImmSetConversionStatus) that can help here....

But let's look more to the services TSF provides for Applications, specifically the Language Bar services. Although the examples on that page talking about speech are misleadingly unhelpful, the GUID_COMPARTMENT_* links from that page point to the Predefined Compartments page which has several promising compartments like GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION and GUID_COMPARTMENT_KEYBOARD_INPUTMODE_SENTENCE, and these compartments are actually about as useful as they sound and more so. :-)

At some point I'll have to put together a sample using these, though Eric Brown in this blog points to a sample showing how they can be used from within a text service. I'll just put the idea of an application style sample on my list of things to do....

no comments

go to newer or older post, or back to index or month or day