Always want to write a little about the input method programming things, today finally a little time, hope to a little help later. In this special thanks to the "free Pinyin" author Li Zhenchun, I just started a few problems are in his help to solve.
First we need to understand what the input method is. At present, there are basically two types of input method: external type (such as the early universal Wubi) and Input Method interface (input methods editor-ime). Plug-in relatively simple, is an EXE file, by simulating some windows input message to the current active editing window input text, a significant advantage is that the input method as long as the start, you can use in all processes, but the shortcomings should not be overlooked, the first to achieve it is not easy, A larger disadvantage is that compatibility is not good enough, usually a version of Windows requires a version of the input, in addition to this type of input method in order to be able to intercept user input, usually need to hook the keyboard hook, easy to cause system instability or inefficient. Most of the input method or IME to implement, the following article mainly discusses the IME programming need to pay attention to problems and solutions.
What is an IME? An IME is a standard input method interface specification that is used on a Windows platform. It is essentially a dll,windows defines a series of interfaces for this DLL, and different interfaces implement the specified functionality. Programmers need to implement these interfaces and export them as input methods when writing input method programs. The definition of a specific interface is not the focus of this article, and if you need to understand that you just need to search the Web for "Input Method Programming Guide", you can understand that more information is referenced by MSDN.
The most difficult problem with
Just starting input method programming is that the program framework is set up and doesn't know how to use and Debug. A very important issue here is the installation of input methods. The input method is a Windows plug-in that requires advanced line registration for Windows to recognize and use. To do this, you need to copy your generated DLL to the system directory (Windows\System32) and then invoke the API Imminstallime, which in my practice is a simple program to do the installation work, Called once after each input method recompilation completes to complete the input method registration. One more thing to note here is that Windows provides a mechanism that allows an input program to stop quitting once it's started, which means that if your program code changes and needs to be reinstalled, you'll have to restart your computer. An interface in an IME-defined interface is an initialization that provides an IME, which is the bool WINAPI Imeinquire (lpimeinfo lpimeinfo,lptstr lpszuiclass,lpctstr lpszoption), The following code comes from the input method I wrote:
BOOL WINAPI ImeInquire(LPIMEINFO
lpIMEInfo,LPTSTR lpszUIClass,LPCTSTR lpszOption)
{
lpIMEInfo->dwPrivateDataSize = sizeof(CONTEXTPRIV);//系统根据它为INPUTCONTEXT.hPrivate分配空间
lpIMEInfo->fdwProperty = IME_PROP_KBD_CHAR_FIRST |
#ifdef _UNICODE
IME_PROP_UNICODE |
#endif
IME_PROP_SPECIAL_UI |
IME_PROP_END_UNLOAD ;
lpIMEInfo->fdwConversionCaps = IME_CMODE_FULLSHAPE |
IME_CMODE_NATIVE;
lpIMEInfo->fdwSentenceCaps = IME_SMODE_NONE;
lpIMEInfo->fdwUICaps = UI_CAP_2700;
lpIMEInfo->fdwSCSCaps = 0;
lpIMEInfo->fdwSelectCaps = SELECT_CAP_CONVERSION;
_tcscpy(lpszUIClass,CLSNAME_UI);
return TRUE;
}