天天加油 - 助您成才
Delphi下编程实现中文输入
您正在看的DELPHI是:Delphi下编程实现中文输入。

  BorlandDelphi以其强大的功能及和高效的可 视化开发环境为广大程序设计员所青睐。尤其是它封装了WINDOWSAPI函数,能方便地利 用Windows资源,大大加快了程序开发速度。

  在平时的计算机操作中,中文输入是不可避免的。 使用者可能喜欢不同的中文输入法(inputmethodeditor,简称IME),这就不得不经常点击 任务栏中的中文图标或用CTRL+Space,CTRL+Shift热键切换,初学者用起来很不方便。针对 这一问题,可以在开发软件时,在程序中设置用户喜欢的中文输入法,方便用户的使用。Delphi 中只有少数控件如TEdit支持IME,而且该功能不强,不能在运行时更改输入法。

  笔者通过实践和摸索,查找了相关的IME资料,利 用了WindowsAPI函数,实现了IME的功能。

  常用函数有:

  API函数:BOOLImmSimulateHotKey

  (HWNDhWnd,DworddwHotKeyID);//模拟热键

  其中Hwnd为程序窗口的句柄,dwHotHKeyID

  为模拟的热键,若成功则返回True

  HKLGetKeyboardLayout(DworddwLayout);

  //获得当前键盘状态

  BOOLImmIsIME(HKLhKL);

  //判断当前是否处于中文输入状态,若是则返回True

  自定义函数:

  打开相应输入法:OpenIme(imename:string),

  例OpenIme(全拼输入法);

  关闭中文输入法:CloseIme;

  以下是一个简单的例子,仅起参考作用。

  使用时uses中加上imm

  具体的实现方法及源代码如下:

  unitUnit1;

  interface

  uses

  Windows,Messages,SysUtils,Classes,

  Graphics,Controls,Forms,Dialogs,

  StdCtrls,Buttons,imm;

  type

  TForm1=class(TForm)

  ComboBox1:TComboBox;

  BitBtn1:TBitbtn;

  BitBtn2:TBitbtn;

  BitBtn3:TBitbtn;

  procedureFormShow(Sender:TObject);

  procedureOpenIme(imename:string);

  procedurecloseIme;

  procedureComboBox1Change(Sender:TObject);

  procedureBitbtn1Click(Sender:TObject);

  procedureBitbtn2Click(Sender:TObject);

  procedureBitbtn3Click(Sender:TObject);

  private

  {Privatedeclarations}

  public

  {Publicdeclarations}

  end;

  var

  Form1:TForm1;

  implementation

  {$R*.DFM}

  procedureTForm1.FormShow(Sender:TObject);

  var

  j:integer;

  begin

  forj:=0toscreen.imes.count-1do

  begin

  ComBoBox1.Items.Add(screen.Imes.strings[j]);

  //获取系统中已安装的中文输入法

  end;

  end;

  procedureTform1.OpenIme(imename:string);

  var

  I:integer;

  myhkl:hkl;

  begin

  ifImeName<>then

  begin

  ifScreen.Imes.Count<>0then

  begin

  I:=scr .Imes.indexof(imename);

  ifI>=0then

  myhkl:=hkl(screen.Imes.objects[i]);

  activatekeyboardlayout(myhk

[1] [2] 下一页

  • 热门文章
  • 最近更新
  • 推荐阅读
  • DELPHI《Delphi下编程实现中文输入》Delphi下编程实现中文输入
    关于我们 | 版权申明 | 广告服务 | 友情链接 | 网站地图 | 使用帮助 | ©2006-2008 TTADD.COM