Automatic switching of Chinese and English input method

zhaozj2021-02-11  232

Automatic switching of Chinese and English input method

Preface:

When developing database programs, you often need to input Chinese and English. To this end, the operator has to constantly switch between the two, can you implement the automatic switching of the Chinese and English input method? That is, if you need to enter a Chinese input method, the Chinese input method is automatically turned off in English, and returns to the English input method. I use C Builder5 automatic switching function of the Chinese and English input method according to the actual requirements of the operator, and each operator can customize the Chinese input method he used to him according to his Chinese input method. Really realized automatic switching of multi-user in English input method.

Program design ideas:

Each input control has two attributes IMEMODE and IMENAME, where iMemode indicates that several values ​​related to China are: Imdisable, Imclose, Impan, Imdontcare, Imchinese. If the IMEMode property is set to iMCHINESE, the input method of this control is Chinese, and the IMename property reflects what Chinese input method; set the IMEMODE to Imclose, then turn off the open Chinese input method, return to the English input method status. Since each operator's Chinese input method is not the same, IMENAME cannot be specified in the program, so it is necessary to dynamically specify the IMENAME attribute value of the input control at the run phase.

Program implementation:

C Builder has a global variable Screen, its property IME reflects the input method of the system. In the program, you will first get the input method of the system installation, and the user selects the Chinese input method he like according to his preference, and writes the user's choice to an INI file. The bottle assigns this value to the IMENAME of the input control from this INI file, which is dynamically specified IMENAME.

n Newly built a form, named Form_ime, put a Combox control on Form_ime uses to get the system's input method, then drag two Button control Button1 and Button2, set its CAPTION attribute to "modify" and "Off".

The program source code is as follows:

/ / -------------------------------------------------------------------------------------------- ---------------------------

#include

#pragma HDRSTOP

#include "IME.H"

#include

#include "dm.h"

/ / -------------------------------------------------------------------------------------------- ---------------------------

#pragma package (smart_init)

#pragma link "statusbarex"

#pragma resource "* .dfm"

TFORM_IME * FORM_IME;

/ / -------------------------------------------------------------------------------------------- ---------------------------

__fastcall tform_ime :: TFORM_IME (Tcomponent * Owner)

: TFORM (OWNER)

{

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform_ime :: FormShow (TOBJECT * SENDER)

{

// Get the system input method and assign it to combox1-> itemscomboBox1-> items-> assign (screen-> IMES);

// Open the Imesetup.ini file, if there is no existence, you automatically create this file ----

TiniFile * PiniFile = New

TiniFile (Application-> Exename) "Imesetup.ini");

/ / Read the previously saved input method name, will be displayed in the Combox1 box

ComboBoX1-> text = Pinifile-> ReadString ("IME", "Chinese", "");

Delete Pinifile;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform_ime :: formclose (Tobject * Sender, Tclosection & Action)

{

Action = cafree; // Automatically release the memory space occupied by FORM

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform_ime :: Button2Click (TOBJECT * SENDER)

{

CLOSE ();

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform_ime :: Button1Click (Tobject * Sender)

{

// If the user re-specifies the input method, rewrite the selected input method back to IMESETUP.INI file

TiniFile * PiniFile = New

TiniFile (Application-> Exename) "Imesetup.ini");

Pinifile-> Writestring ("IME", "Chinese", ComboBox1-> text);

Delete Pinifile;

/ / Simultaneously assign the selected input method to the chiMename variable in Data Module DM1

DM1-> chimename = comboBox1-> text;

/ / Display the Chinese prompt box, indicating that the default Chinese input method is successful

MessageBoxEx (Handle, "Default Chinese Input Method Successful",

this-> caption.c_str (), MB_ICONITIONFORMATION MB_OK, 0X0404);

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

n Read the IMESETUP.INI file in the constructor of the data module, assign the input method selected by the user to the Chimename variable.

__fastcall TDM1 :: TDM1 (Tcomponent * Owner)

: TDATAMODULE (OWNER)

{

// ---- Read the default Chinese input method -----

TiniFile * PiniFile = New

TiniFile (Application-> Exename) "Imesetup.ini");

Chimename = Pinifile-> ReadString ("IME", "Chinese", ""); delete Pinifile;

}

// -----------------------------------------

n In the course input module, specify the Chinese input method of the input control in the FormShow () event, other controls that need to enter English can specify its IMEMODE = Imclose in the design phase;

// --- Specify course name default Chinese input method -----

Void __fastcall tcourseForm :: FormShow (TOBJECT * SENDER)

{

DBEDIT2-> IMENAME = DM1-> chimename;

DBGRID1-> Column-> items [1] -> IMENAME = DM1-> chimename;

}

/ / -------------------------------------------------------------------------------------------- -----

This method can be used in other input modules that need to be used in Chinese input, simple and practical

Compile the running program, feel the automatic switching of the Chinese and English input method!

Automatic switching of Chinese and English input method

Http://tech.sina.com.cn 2000/11/15

Software world

Luo name group

Foreword: When developing a database program, you often need to enter Chinese and English. To this end, the operator has to constantly switch between the two, can you implement the automatic switching of the Chinese and English input method? That is, if you need to enter a Chinese input method, the Chinese input method is automatically turned off in English, and returns to the English input method. I use C Builder5 automatic switching function of the Chinese and English input method according to the actual requirements of the operator, and each operator can customize the Chinese input method he used to him according to his Chinese input method. Really realized automatic switching of multi-user in English input method. Program Design Idea: Each input control has two attributes IMEMODE and IMENAME, where IMEMODE indicates that several values ​​related to China are: Imdisable, Imclose, Impan, Imdontcare, Imchinese. If the IMEMode property is set to iMCHINESE, the input method of this control is Chinese, and the IMename property reflects what Chinese input method; set the IMEMODE to Imclose, then turn off the open Chinese input method, return to the English input method status. Since each operator's Chinese input method is not the same, IMENAME cannot be specified in the program, so it is necessary to dynamically specify the IMENAME attribute value of the input control at the run phase. Program Implementation: C Builder has a global variable Screen, its property IME reflects the input method of the system. In the program, you will first get the input method of the system installation, and the user selects the Chinese input method he like according to his preference, and writes the user's choice to an INI file. The bottle assigns this value to the IMENAME of the input control from this INI file, which is dynamically specified IMENAME. N Newly built a form, named Form_ime, put a Combox control on Form_ime uses to get the system's input method, then drag two Button control Button1 and Button2, set its CAPTION attribute to "modify" and "Off". The program source code is as follows: // ----------------------------------------- -------------------------------- # include # prgma hdrstop #include "IME.H" #include

#include "dm.h" // ----------------------------------------- ---------------------------------- #pragma package (smart_init) #pragma link "statusbarex" #pragma resource " * .dfm "TFORM_IME * form_ime; // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------- __fastcall tform_ime :: tform_ime (tComponent * Owner): TFORM (OWNER) {} // ------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------- void __fastcall tform_ime :: formst * sender {// Get the system's input method, and Give Combox1-> Items ComboBoX1-> Items-> Assign (screen-> IMES); // Open the Imesetup.ini file, if there is no existence, automatically create this file ---- TiniFile * Pinifile = New TiniFile (ExtractFilePath Application-> Exename) "IMESETUP.INI"); // Read the previously saved input method name, will be displayed in the Combox1 box, ComboBox1-> text = Pinifile-> ReadString ("IME", "Chinese", "" ); Delete pinifile;} // ------------------------------------------ --------------------------------- void __fastcall tform_ime :: formclose (Tbobject * sender, tclosection "{action = Cafree ; // Automatically release the memory space occupied by FORM} // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------- void __fastcall tform_ime :: Button2click (TOBJECT * Sender) {close ();} // ------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------- void __fastcall tform_ime :: Button1click (TOBJECT * Sender) {// The user re-specifies the input method, rewrite the selected input method back to Imesetup.ini file tinifile * Pinifile = new tinifile (applfilepath (application-> Exename) "Imesetup.ini"); PiniFile-> WritestRing ("IME", "Chinese", comboBox1-> text); delete pinifile;

转载请注明原文地址:https://www.9cbs.com/read-4874.html

New Post(0)