现在将源代码公布出来,来谢谢大家的支持。本人水平有限,大家有什么号的灵感或建议,请 email wang517@21cn.com.多谢!!
原代码实现的思路:
提供一个列举系统所有输入法的窗体,供用户选择,将选择的中文输入法保存到系统注册表里。
提供一个方法 ChangeYouFormAllControlIme(form) ,form 是需要输入的窗体名称,枚举出相应窗体具有输入法的控件。
提供一个方法 JugeClassType(PClass:Tcontrol),判断每一个控件的实际类型,根据其ImeMode(为了程序设计简便,当值 为imchinese 时,切换为用户选择的中文输入法 ,其它切换为英文)
下面是主要原代码:
//判断控件类型切换中英文这个只能具体判断,无法用 Twincontrol 笼统判别或概括
procedure JugeClassType(PClass:Tcontrol;
begin
if pclass is TEdit then
begin
if TEdit(pclass).ImeMode=imchinese then
TEdit(pclass).ImeName:=StrImeName (StrImeName 注册表保存的中文输入法名)同)
else
TEdit(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TMemo then
begin
if TMemo(pclass).ImeMode=imchinese then
TMemo(pclass).ImeName:=StrImeName
else
TMemo(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TComboBox then
begin
if TComboBox(pclass).ImeMode=imchinese then
TComboBox(pclass).ImeName:=StrImeName
else
TComboBox(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TRichEdit then
begin
if TRichEdit(pclass).ImeMode=imchinese then
TRichEdit(pclass).ImeName:=StrImeName
else
TRichEdit(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TDBGrid then
begin
if TDBGrid(pclass).ImeMode=imchinese then
TDBGrid(pclass).ImeName:=StrImeName
else
TDBGrid(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TDBEdit then
begin
if TDBEdit(pclass).ImeMode=imchinese then
TDBEdit(pclass).ImeName:=StrImeName
else
TDBEdit(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TDbMemo then
begin
if TDbMemo(pclass).ImeMode=imchinese then
TDbMemo(pclass).ImeName:=StrImeName
else
TDbMemo(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TDbcombobox then
begin
if TDbcombobox(pclass).ImeMode=imchinese then
TDbcombobox(pclass).ImeName:=StrImeName
else
TDbcombobox(pclass).ImeMode:=imClose;
exit;
end;
if pclass is Tdblookupcombobox then
begin
if Tdblookupcombobox(pclass).ImeMode=imchinese then
Tdblookupcombobox(pclass).ImeName:=StrImeName
else
Tdblookupcombobox(pclass).ImeMode:=imClose;
exit;
end;
if pclass is Tdbrichedit then
begin
if Tdbrichedit(pclass).ImeMode=imchinese then
Tdbrichedit(pclass).ImeName:=StrImeName
else
Tdbrichedit(pclass).ImeMode:=imClose;
exit;
end;
if pclass is TMaskEdit then
begin
if TMaskEdit(pclass).ImeMode=imchinese then
TMaskEdit(pclass).ImeName:=StrImeName
else
TMaskEdit(pclass).ImeMode:=imClose;
exit;
end;
end;
//这个方法,您只需要在需要切换中英文的窗体 oncreate 事件里调用就可以了。YFormName,需要切换中英文的窗体。
Procedure ChangeYouFormAllControlIme(YFormName:TWinControl);
var
i:integer;
ChildControl:TControl;
Reg:TRegistry;
YouFormOrOTher:Twincontrol;
begin
YouFormOrOTher:=YFormName;
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
try
if Reg.OpenKey('\Software\IMeCustom',false)=true then
StrImeName:=reg.ReadString('CustomIMeName');
finally
reg.CloseKey;
reg.Free;
end;
for i:=0 to YouFormOrOTher.ControlCount-1 do
begin
ChildControl:=YouFormOrOTher.Controls[i];
JugeClassType(ChildControl);
if ChildControl is TWinControl then ChangeYouFormAllControlIme(ChildControl as TWinControl);
end;
end;
end.
枚举输入法,并将用户的选择保存到注册表里,很简单,这个大家可以自己实现。例如
ListBox1.Items:=screen.Imes;