A Typing Program Sample based on Win32 Multilingual IME
(the IME mechanism in this example is outdated and not working in Windows Vista. Please refer to the TSF example)
By Y Lam (firstname.lastname@example.org), Hong Kong, China (Last Update: 2003-07-08)
This tutorial is based on a sample code YLam Input. You enter an email address below to get a link to download it.
I will first describe what YLam Input does, how to install etc. Later on, I will talk about the code.
What does YLam Input sample code do:
If you are familiar with Far East (Chinese, Japanese and Korean) Version of Windows 95/98/ME, you may notice that there are some *.ime files in windows\system directories. They are actually programs that change your keystrokes to some characters that output to different applications. The sample code is a demonstration on how to write these *.ime files.
Here is a screen capture (in Traditional Chinese Windows) of YLam Input:
It will show up a yellow rectangular area with a red line that can be moved around when dragged
When you hit any key, it will send the word "apple" to the application
They key you have typed will be shown in the yellow rectangular area as well.
Purpose of the sample code:
Provide sample code to programmers who are:
strong in C, C++ programming
have knowledge but not so familiar with Windows MFC programming, Windows DLL Programming
have no idea in Windows IME mechanism.
to develop his/her own input method. The sample code provided ideas on how to implement basic functionalities like how to
capture all key stroke
draw simple UI and implement basin UI functionality like dragging
send strings to applications
that is need by any input method. Programmers can add functionality like lookup tables to this sample and write his own input method.
However, many of Win32 IME feature are not shown:
floating input windows
modification of composition strings
Please find relevant sample codes from Microsoft.
How to compile the sample code:
You MUST have Visual C/C++ 6.0 or later. I assume you have installed it
D:\Program Files\Microsoft Visual Studio\VC98
and your windows is in C:\windows
Here are the steps to compile and install the sample code:
unzip the sample code downloaded above.
copy imm\imm.h unzipped to D:\Program Files\Microsoft Visual Studio\VC98\include
copy imm\imm32.lib to D:\Program Files\Microsoft Visual Studio\VC98\lib
start Visual C/C++ and open the file ylam/ylam.dsw
Make sure you choose the correct block header of ylam.dll for your language version of windows:
under "Build" menu in Visual C, click "Build ylam.dll"
copy ylam\release\ylam.dll to c:\windows\system\ylam.ime
For UNICODE, make sure when installing Visual C/C++ 6.0, you
installed the UNICODE library
How to install the sample code:
run register\register.exe to register ylam.ime
now add this input method in My Computer -> Control Panel -> Input Method
start your input method like using Control-Shift Key or as follow:
Explanation of the source code:
The following is based on my understanding of Win32 IME from various sources and sometimes what is described here may be even WRONG! Please refer to Microsoft documentation if required.
Here is the picture of Win32 IME in my mind:
For each input method, there is one instance of IME Conversion Interface. When a user in an application (for example Microsoft Word, Internet Explorer etc) started a Input Method, a "Input Context" will be created. The IME conversion interface communicates with the Windows Application through these Input Context.
IME Conversion Interface
An *.ime file actually is a Windows DLL. It should provide the following functions so that the Windows 95/98/ME can recognize it as a Input Method:
You MUST declare them in a *.def file in the Visual C/C++ project. For some of them, I don't even what they do, but some of them (those bolded) are important ones and must be implemented. I will explain them later.
IME UI"An IME is expected to register its own UI class for the system. The UI class provided by each IME should be responsible for IME-specific functionality. The IME should register the classes that are used by IME itself when the IME is attached to the process. This occurs when DLLEntry is called with DLL_PROCESS_ATTACH. The IME then has to set the UI class name in the lpszClassName parameter, which is the second parameter of ImeInquire." (from Win32 Multilingual IME Overview for IME Development, MSDN)
What is the order of the functions are called?
I think the best way to make people understand how the source code work is to describe what functions are called, starting from a user switch a IME on in a application, hit a key and then how a string is sent to the application.