以下代码经过测试
procedure SetMyIme(ImeName:string);
var
i:integer;
HandleToSet:HKL;
begin
if not SysLocale.FarEast then Exit;
if ImeName<>' ' then
begin
if (AnsiCompareText(ImeName,Screen.DefaultIme)<>0) and (Screen.Imes.Count<>0)
then
begin
HandletoSet:=Screen.DefaultKbLayout;
i:=Screen.Imes.IndexOf(ImeName);
if i>=0 then HandletoSet:=HKL(Screen.Imes.Objects);
ActivateKeyboardLayout(HandleToSet,KLF_ACTIVATE);
end;
end;
end;
procedure ResetMyIme(ImeName:string);
begin
if not SysLocale.FarEast then Exit;
if ImeName<>' ' then
begin
if (AnsiCompareText(ImeName,Screen.DefaultIme)<>0) then
ActivateKeyboardLayout(Screen.DefaultKbLayout,KLF_ACTIVATE);
end;
end;
procedure TForm1.Memo1Click(Sender: TObject);
begin
SetMyIme('微软拼音输入法');
end;
在use下面你必须手工添加:IMM
ActivateKeyboardLayout的帮助文件在Windows SDK里面,你自己看吧