Objective:
In the development of the database program, often need to input Chinese and English, for this, the operator has to switch between the two, can not realize the automatic switching of English input method? That is, in the need to enter Chinese local system to open the Chinese input method, in the need to enter English in the local system automatically shut down the Chinese input method, back to the English IME. I am in the development of curriculum input module, according to the actual requirements of the operator to use C + + BUILDER5 to achieve the automatic switching function of the Chinese and English input method, each operator can be used to customize his custom in accordance with the Chinese input method, so that the real realization of the multi-user in the English input method of automatic
Program Design Ideas:
Each input control has two properties IMEMode and Imename, where IMEMode indicates the current input method, and several values related to China are: imdisable, Imclose, Imopen, Imdontcare, Imchinese. If you set the IMEMode property to Imchinese to indicate that the input method for this control is Chinese, and the Imename property reflects what Chinese input method is, and the IMEMode is set to Imclose, you can turn off the Chinese input method that has been opened and return to the English IME status. Because the Chinese input method of each operator is not the same, you cannot specify Imename in the program, so you need to dynamically specify the Imename property value of the input control at run time.
Program implementation:
C + + Builder has a global variable screen whose property IME reflects the input method of the system. The program first obtains the system installs the input method, the user chooses according to his liking the Chinese input law, the user's choice writes in one INI file. In the need to switch to Chinese input from this INI file to read data, the bottle will assign this value to the input control of the imename, thus enabling the dynamic designation Imename.
n Create a new form, named Form_ime, put a Combox control on the Form_ime Combox1 used to get the input method of the system, drag two button controls Button1 and Button2, and set their caption properties to "modify" and "close" respectively "。
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 input method of the system and assign it to Combox1->items
Combobox1->items->assign (Screen->imes);
Open the Imesetup.ini file, or if it does not exist, automatically create the file----
Tinifile *pinifile = new
Tinifile (Extractfilepath (application->exename) + "Imesetup.ini");
Read the previously saved input method name, which will appear in the Combox1 box
Combobox1->text=pinifile->readstring ("IME", "Chinese", "");
Delete Pinifile;
}
//---------------------------------------------------------------------------
void __fastcall Tform_ime::formclose (tobject *sender, tcloseaction &action)
{
Action=cafree; Automatically frees up the form's memory space when exiting
}
//---------------------------------------------------------------------------
void __fastcall Tform_ime::button2click (tobject *sender)
{
Close ();
}
//---------------------------------------------------------------------------
void __fastcall Tform_ime::button1click (tobject *sender)
{
If the user re-specify the input method, the selected input method is written back to the Imesetup.ini file
Tinifile *pinifile = new
Tinifile (Extractfilepath (application->exename) + "Imesetup.ini");
Pinifile->writestring ("IME", "Chinese", combobox1->text);
Delete Pinifile;
At the same time, the selected input method is assigned to the Chimename variable in the data module DM1
dm1->chimename=combobox1->text;
Display the Chinese prompt box to indicate that the default Chinese input method has been successfully modified
Messageboxex (handle, "default Chinese Input Method modified successfully",
This->caption.c_str (), mb_iconinformation+mb_ok,0x0404);
}
//---------------------------------------------------------------------------
N reads the Imesetup.ini file in the constructor of the data module, assigns the input method of the user selection to the Chimename variable
__fastcall tdm1::tdm1(tcomponent* owner)
: tdatamodule(owner)
{
//---- 读取默认中文输入法-----
tinifile *pinifile = new
tinifile(extractfilepath(application->exename)+"imesetup.ini");
chimename=pinifile->readstring("ime", "chinese", "");
delete pinifile;
}
//-----------------------------------------
N in the course input module, specify the input control's Chinese input method in the Formshow () event, and other controls that need to be entered in English can specify their imemode=imclose in the design phase;
//---指定课程名称默认中文输入法-----
void __fastcall tcourseform::formshow(tobject *sender)
{
dbedit2->imename=dm1->chimename;
dbgrid1->columns->items[1]->imename=dm1->chimename;
}
//-----------------------------------------------------
This method can be used in other input modules where Chinese input is required, simple and practical
Compile and run the program, feel the Chinese and English input method of automatic switching feel it!