可以使用Windows API函数<br>ActivateKeyboardLayout,GetKeyBoardLayoutList,GetKeyboardLayout,ImmGetDescription<br>以下是例程。<br>在Form1上放置一个ComboBox,设置ComboBox1的Style属性 = csDropDownList<br>在uses语句里填加Imm单元.<br>下面是Unit1.pas<br>//*******************************************************************<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls,imm;<br><br>type<br> TForm1 = class(TForm)<br> ComboBox1: TComboBox;<br> Memo1: TMemo;<br> procedure FormShow(Sender: TObject);<br> procedure ComboBox1Change(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> KBLL: array [1..16] of integer;<br> IMENameArray: array [1..16] of String;<br> IMECount: Integer;<br><br>implementation<br><br>{$R *.dfm}<br>//清除数组过程<br>procedure ClearArray();<br>var<br> i:Integer;<br>begin<br> for i:=1 to 16 do<br> begin<br> KBLL:=0;<br> IMENameArray:='';<br> end;<br>IMECount:=0;<br>end;<br><br>//枚举输入法<br>procedure LoadIME();<br>var<br> i,IMENum: Integer;<br> strRtn: array [0..255] of char;<br>begin<br>ClearArray; //清除数组<br>IMENum:=GetKeyBoardLayoutList(32,KBLL[1]); //取得系统输入法总数<br>if IMENum>0 then<br> for i:=1 to IMENum do<br> begin<br> ImmGetDescription(KBLL,strRtn,255);<br> if trimleft(strRtn)='' then<br> IMENameArray:='英文输入法'<br> else<br> IMENameArray:=trimleft(strRtn);<br> IMECount:=i;<br> end;<br>end;<br><br>//改变当前输入法<br>//Index 为前面定义的IMEName的下标<br>procedure ChangeIME(Index: Integer);<br>begin<br>ActivateKeyboardLayout(KBLL[Index],1);<br>end;<br><br>//获取当前输入法名称,如果失败,返回-1<br>function GetActiveIMEName():Integer;<br>var<br> lngRtn,i: Integer;<br>begin<br>Result:=-1;<br>lngRtn:=GetKeyboardLayout(0);<br>for i:=1 to IMECount do<br> if KBLL=lngRtn then<br> Result:=i;<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>var<br> i: integer;<br>begin<br>LoadIME();<br>if IMECount>0 then<br> for i:=1 to IMECount do<br> ComboBox1.Items.Add(IMENameArray);<br>ComboBox1.ItemIndex:=GetActiveIMEName();<br>end;<br><br>procedure TForm1.ComboBox1Change(Sender: TObject);<br>begin<br>ChangeIME(comboBox1.ItemIndex+1);<br>end;<br>end.