关于输入法的API(300分)

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

lzjjyy

Unregistered / Unconfirmed
GUEST, unregistred user!
在窗体关闭问输入法会还原,我想是否有可能不还原,而的新设的输入法,<br>而且我也不想给每一个TEDIT控件都设一次,如问做?<br><br>急要300分奉上
 
设定tedit.imename:=输入法.<br>&nbsp; &nbsp; tedit.imemode:=imopen;<br>第一次启动程序时就保存tedit的imename,然后用全局变量保存,开窗体时<br>设定所有的tedit类控件的imename为你保存的值就行了.
 
设定所有的tedit类控件的imename为你保存!<br><br>是用组件循环的处理方式???
 
也不一定就是TEdit才行,只要需要输入中文的地方都可以的。<br>
 
这样做我也知道,但是不方便,我想有没有如某个API一次就可使当前的输入法设置为所需的[:(]
 
&gt;&gt;我想有没有如某个API一次就可使当前的输入法设置为所需的[:(]<br>按推理,应该是没有,因为你可以自己写循环实现。<br>我现在用的程序就是先取得用户选择的输入法,然后在FORM的ONSHOW事件中循环,给每个<br>需要的控件赋值。
 
可以使用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>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls,imm;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ComboBox1: TComboBox;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; &nbsp; procedure ComboBox1Change(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; KBLL: array [1..16] of integer;<br>&nbsp; IMENameArray: array [1..16] of String;<br>&nbsp; IMECount: Integer;<br><br>implementation<br><br>{$R *.dfm}<br>//清除数组过程<br>procedure ClearArray();<br>var<br>&nbsp; &nbsp;i:Integer;<br>begin<br>&nbsp; &nbsp; &nbsp;for i:=1 to 16 do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KBLL:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IMENameArray:='';<br>&nbsp; &nbsp; &nbsp;end;<br>IMECount:=0;<br>end;<br><br>//枚举输入法<br>procedure LoadIME();<br>var<br>&nbsp; &nbsp; i,IMENum: Integer;<br>&nbsp; &nbsp; strRtn: array [0..255] of char;<br>begin<br>ClearArray; //清除数组<br>IMENum:=GetKeyBoardLayoutList(32,KBLL[1]); //取得系统输入法总数<br>if IMENum&gt;0 then<br>&nbsp; &nbsp;for i:=1 to IMENum do<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ImmGetDescription(KBLL,strRtn,255);<br>&nbsp; &nbsp; &nbsp; &nbsp; if trimleft(strRtn)='' then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IMENameArray:='英文输入法'<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IMENameArray:=trimleft(strRtn);<br>&nbsp; &nbsp; &nbsp; &nbsp; IMECount:=i;<br>&nbsp; &nbsp;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>&nbsp; &nbsp;lngRtn,i: Integer;<br>begin<br>Result:=-1;<br>lngRtn:=GetKeyboardLayout(0);<br>for i:=1 to IMECount do<br>&nbsp; &nbsp; if KBLL=lngRtn then<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=i;<br>end;<br><br>procedure TForm1.FormShow(Sender: TObject);<br>var<br>&nbsp; &nbsp;i: integer;<br>begin<br>LoadIME();<br>if IMECount&gt;0 then<br>&nbsp; &nbsp;for i:=1 to IMECount do<br>&nbsp; &nbsp; &nbsp; 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.
 
后退
顶部