At least three input methods are generally installed in the Windows system, and the input method is often switched when entering the data. Although the Windows system provides switching fast, it has brought a lot of trouble to input work. If you provide users with intelligent input methods for users to switch, such applications is more professional and more competitive. I don't know if you can use Access, and the Access automatic switching method is automatically switched when you need to enter English. If you need to enter English, if another field needs to enter Chinese automatically switch to a Chinese input state. This article will discuss the technology of how to dynamically control input method in a Windows application. Many controls in Delphi have the properties of the control input method, and the user can set this property when designing, but does not directly provide control over the input method in the VC, and implement this function in the VC application Call the Windows API. In this article, I will use a class to encapsulate the Windows API function associated with the input method. The reader can directly import this class into the project engineering, and the control of the input method can be implemented by operating this class. This is more suitable for object-oriented objects. Development. To control the input method, the first question to be solved is if you get the input method information installed. Under the Windows platform, each installed input method registers related information in the registry. This information can be found under the "HKEY_CURRENT_USER / Keyboard Layout / preload" key, and the key is made as a value name (temporary name digital number) at 1-based, and the content of its value is eight numbers. The consisting of strings (temporary named code, such as "E0040804"), where left 4 bits are Device Identifier, and the right 4 bits are language code (Language Identifier). For example, the left E004 refers to the intelligent ABC, and the right 0804 refers to the Chinese in the mainland. Detailed explanation for all code in MSDN, if you are interested, please visit MSDN related content. Also, it is to explain that the input method registration information in the Windows98 version is slightly different from the above description. It is the digital number of the installed input method as the subkey below ... / preload, and the number of digital numbers is ... The value under the / preload key. By reading the input method information in the registry, all installed input methods can be listed, but the obtained input method is only some of the difficult digital strings, how to translate these numeric strings into easy-to-understand text descriptions? ? Similarly, in the hkey_local_machine: "System / CurrentControlSet / Control / Keyboard Layouts /" key, it is registered, and its subkey is named Enter the method of keyboard, the content is the IME file, name and other information of the input method. At this point, we have learned the principle knowledge of the Windows system control input method. Here we start to create a C class that control input method, the main steps are as follows: 1. Create a new class, the new class name: CinputLanguage 2. Create a new structure for saving input method. When loading the system installed input method information, the input method information is saved with a linked list of this structure.
Struct il {char ilid [15]; // Enter the approximate number. Char szname [100]; // Description text of the input method. IL * pnext;}; 3. Add a private member variable IL * m_pilhead; 4. Add to load the member function of the information list information
// This function is only for Windows2000 or higher, if you want to contact the author in the Windows 98 version. BOOL CInputLanguage :: LoadInputLanguage () {HKEY hKey, hKey1; DWORD cp = 16; char lp [15]; CString szID; CString szKeyName, szKeyName1; szKeyName = "Keyboard Layout // Preload"; szKeyName1 = "System // CurrentControlSet / / Control // keyboard layouts // "; int i = 1; szid.format ("% d ", i); dword lpt = reg_sz; if (: regopenkey (HKEY_CURRENT_USER, SZKEYNAME, & HKEY) == Error_suCcess) {while (:: RegQueryValueEx (hKey, szID, NULL, & lpT, (LPBYTE) lp, & cp) == ERROR_SUCCESS) {CString szTempName; szTempName = szKeyName1 (LPCTSTR) (LPTSTR) lp; if (RegOpenKey (HKEY_LOCAL_MACHINE, szTempName, & hKey1) == Error_suCcess) {char LPD [100]; DWORD LPS = 100; // DataSize IF (RegQueryValueex (HKEY1, "Layout Text", NULL, & LPT, (LPBYTE) LPD, & LPS) == Error_Success) {il * p1, * p2; p1 = m_pilhead; p2 = new (il); strcpy (p2-> ilid, lp); strcpy (p2-> szname, lpd); p2-> pnext = null; if (p1) {while (p1- > pnext) {p1 = p1-> pnext;} p1-> pnext = p2;} else {m_pilhead = p2;}}} :: regclosekey (HKEY1); i ; szid.format ("% d", i);}} :: regclosekey (hkey); return (m_pilhead! = Null);} 5. Add Selection Input Method Member Function Bool CinputLanguage :: SelectInputLanguage (IL * PIL) {if (! Pil) Return False; hkl hkl; hkl = loadingKeyboardLayout (pil-> ilid, klf_activate); // Loading input method if (hkl == NULL) RETURN FALSE; Else {ActivateKeyboardLayout (HKL, KLF_SETFORPROCESS); // Activates input method} return true;} 6. Other parts