unitUnit1;
interface
usesWindows,Messages,SysUtils,Classes, Graphics,Controls,Forms,Dialogs,StdCtrls,Buttons,imm;
typeTForm1=class(TForm)ComboBox1:TComboBox;BitBtn1:TBitBtn;BitBtn2:TBitBtn;
BitBtn3:TBitBtn;procedureFormShow(Sender:TObject);
procedureOpenIme(imename:string);procedurecloseIme;procedureComboBox1Change(Sender:TObject);procedureBitBtn1Click(Sender:TObject);procedureBitBtn2Click(Sender:TObject);procedureBitBtn3Click(Sender:TObject);
private{Privatedeclarations}public{Publicdeclarations}end;
varForm1:TForm1;
implementation
{$R*.DFM}
procedureTForm1.FormShow(Sender:TObject);
varj:integer;beginforj:
=0toscreen.imes.count-
1dobeginComBoBox1.Items.Add(screen.Imes.strings[j]); //
获取系统中已安装的中文输入法end;end;
procedureTform1.OpenIme(imename:string);
var
I:integer;
myhkl:hkl;
begin if ImeName<>''then
begin
if Screen.Imes.Count<>0 then
begin
I: =screen.Imes.indexof(imename);
if I>=0 then
myhkl:=hkl(screen.Imes.objects[i]);
activatekeyboardlayout(myhkl, KLF_ACTIVATE);//
设置相应的输入法end;end;end;
procedureTForm1.closeime;
var
myhkl:hkl;
begin
myhkl:=GetKeyBoardLayOut(0);
if ImmIsIME(myhkl) then
// 判断是否在中文状态,若是则关闭它
immsimulateHotkey(handle,IME_CHotKey_IME_NonIME_Toggle);
end;
procedure TForm1.ComboBox1Change(Sender:TObject);
begin
OpenIme(ComboBox1.Text);
end;
procedure TForm1.BitBtn1Click(Sender:TObject);
begin
immsimulateHotkey(handle,IME_CHotKey_shape_Toggle);
// 切换半角和全角模式end;
procedure TForm1.BitBtn2Click(Sender:TObject);
begin
immsimulateHotkey(handle,IME_CHotKey_symbol_Toggle);
//切换中文标点模式和英文标点模式
end;
procedureTForm1.BitBtn3Click(Sender:TObject);
begin
closeime;
end;
end.