如何得到当前打开的输入法?(200分)

  • 主题发起人 主题发起人 LiGen
  • 开始时间 开始时间
L

LiGen

Unregistered / Unconfirmed
GUEST, unregistred user!
在很多软件中,软件能够记住打开的输入法,它的所有界面都使用同一<br>个输入法(用户打开的,不是程序首先设计的)比如word,wps,excel及delphi等等.<br>他们是怎样在程序运行后得到输入法,并把他记住.高分求教,不够可以加.
 
少爷的拐杖 (2002-4-26 23:56:00) &nbsp;<br>//摘录我程序中的一些段落您看看<br>//列出机器中所有的输入法<br>procedure TFm_ImeSet.FormCreate(Sender: TObject);<br>var<br>i,Loop:Integer;<br>ListItem: TListItem;<br>begin<br>Loop:=Screen.Imes.Count;<br>for i:=1 to Loop do<br>&nbsp;begin<br>&nbsp; ListItem := ListView1.Items.Add;<br>&nbsp; ListItem.Caption := Screen.Imes.Strings[i-1];<br>&nbsp;end;<br>end;<br>//保存用户设定的输入法<br>procedure TFm_ImeSet.SpeedButton2Click(Sender: TObject);<br>var<br>AppINI:TIniFile;<br>begin<br>try<br>try<br>AppINI:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'AppSys/login.dll');<br>AppINI.WriteString('UserIme', 'UserIme', ListView1.Selected.Caption);<br>Form1.User_IME:= ListView1.Selected.Caption;<br>except<br>Application.MessageBox('保存设置时发生了一个错误,您的改动无法保存下来。','保存失败',Mb_Ok+Mb_Iconinformation);<br>end;<br>finally<br>AppINI.Free;<br>Close;<br>end;<br>end;<br><br>//调用设置的输入法<br>Procedure TFm_Cable_Experiment.Set_Ime;<br>var<br>i:integer;<br>begin<br>for i:=ComponentCount-1 DownTo 0 do<br>&nbsp; begin<br>&nbsp; if Components.Tag=2 then<br>&nbsp; &nbsp; if (Components is TEdit) then<br>&nbsp; &nbsp; (Components as TEdit).ImeName:=Form1.User_Ime;<br>&nbsp; &nbsp; if (Components is TCombobox) then<br>&nbsp; &nbsp; (Components as TCombobox).ImeName:=Form1.User_Ime;<br>&nbsp; end;<br>end; <br>&nbsp;<br>
 
好象还少了取当前输入法名称这一环节,补上:<br>先定义:<br>var myHKL : HKL;<br>执行:<br>myHKL:=GetKeyBoardLayOut(0);<br>for i := 0 to Screen.Imes.Count-1 &nbsp;do<br>&nbsp; begin<br>&nbsp; &nbsp; if HKL(Screen.Imes.Objects) = myHKL then<br>&nbsp; &nbsp; &nbsp; Edit2.Text := Screen.Imes.Strings;//当前输入法名称<br>&nbsp; end;<br>
 
哈哈!<br>你们这样忙死了,只是给本程序设置输入法而已,如果,我要通过这个程序的运行,来设置<br>另一个程序的输入法呢?并且,输入处理完后,再复原输入法!
 
To sanmzhou<br>应该怎样才好,请赐教。<br>
 
不知道这些代码是否对你有帮助,这本来是回答其他问题的,你参考吧,当然代码是我写的<br>以下代码经过测试<br>procedure SetMyIme(ImeName:string);<br>var<br>&nbsp; i:integer;<br>&nbsp; HandleToSet:HKL;<br>begin<br>if not SysLocale.FarEast then Exit;<br>if ImeName&lt;&gt;' ' then<br>&nbsp; begin<br>&nbsp; &nbsp; if (AnsiCompareText(ImeName,Screen.DefaultIme)&lt;&gt;0) and (Screen.Imes.Count&lt;&gt;0)<br>&nbsp; &nbsp; then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; HandletoSet:=Screen.DefaultKbLayout;<br>&nbsp; &nbsp; &nbsp; &nbsp; i:=Screen.Imes.IndexOf(ImeName);<br>&nbsp; &nbsp; &nbsp; &nbsp; if i&gt;=0 then HandletoSet:=HKL(Screen.Imes.Objects);<br>&nbsp; &nbsp; &nbsp; &nbsp; ActivateKeyboardLayout(HandleToSet,KLF_ACTIVATE);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>procedure ResetMyIme(ImeName:string);<br>begin<br>&nbsp; if not SysLocale.FarEast then Exit;<br>&nbsp; if ImeName&lt;&gt;' ' then<br>&nbsp; begin<br>&nbsp; &nbsp; if (AnsiCompareText(ImeName,Screen.DefaultIme)&lt;&gt;0) then<br>&nbsp; &nbsp; ActivateKeyboardLayout(Screen.DefaultKbLayout,KLF_ACTIVATE);<br>&nbsp; end;<br>end;<br>procedure TForm1.Memo1Click(Sender: TObject);<br>begin<br>SetMyIme('微软拼音输入法');<br>end;<br><br>在use下面你必须手工添加:IMM<br>ActivateKeyboardLayout的帮助文件在Windows SDK里面,你自己看吧
 
后退
顶部