2008年12月17日 星期三

In the previous version of YLam Input method, one of the bugs is when you are typing towards the windows of an application, and then you switch to another application, the YLam Input method windows does not hide itself.

The reason is YLam Input method is based on Microsoft's "Sample Code for Text Services Framework" and there is no examples shows how to auto hide the input method window when the application loses its focus.

After the email discussion with a net friend "zhangruisen", it is known that to support auto show/hide, the "IID_ITfThreadFocusSink" event sink is needed, and in the appropriate functions (i.e. STDAPI CTextService::OnSetThreadFocus() and STDAPI CTextService::OnKillThreadFocus() ), call the show / hide input method window. In Windows SDK, Windows SDK 的 Samples\WinUI\TSFcase, there is an example.

Then in CTextService::Activate(), I called CTextService::_InitThreadFocusSink() and expect that is all! However, no matter how hard I tried to tweak the code, calling _InitThreadFocusSink() always returns S_FAILED. This puzzled me for more that 1/2 years.

Until last evening after back home from work, though very tired, I still tried to compare the Windows SDK's TSF Case example and my YLam Input Method carefully and I finally know what's wroong! It turns out:

In Windows SDK's TSF Case, the part in box above exits and it does not exist in YLam Input Method and other TSF Sample code!!!!!!!! After adding the few lines above, now my YLam input method can do auto show /hide!!!