资源描述:
《vfp汉字输入法类控件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、中文MIS系统大都涉及中西文的混合录入,在进行数据录入特别是大量的数据录入时,需要在中西文输入状态之间来回切换,使用起来非常繁琐。为此,笔者设计了一个汉字输入法类控件,可让用户在中文录入位置自动打开用户喜欢的汉字输入法;在西文录入处,汉字输入法自动关闭。 控件制作 1.启动VFP后,新建一个容器类(container),并命名为“ime”。 2.在容器中添加标签Label1及下拉组合框Combo1,设置属性如下: Label1.Caption=“选择喜欢的输入法” Label1.FontName=“宋体″ Combo1.RowSou
2、rce=“imename” Combo1.RowSourceType=“5-数组” 在Combo1的InteractiveChange事件中写入以下程序: privateselindex selindex=this.listindex this.parent.imehandle=dechandle[selindex] 3.双击容器IME1属性init事件的“默认过程”,写入以下程序代码: DECLAREINTEGERGetKeyboardLayoutListinwin32apiinteger; nbuff,string@poin
3、ter1addi DECLAREINTEGERImmGetDescriptioninimm32integerhkl,string; @lpsz,integernumberaddi DECLAREINTEGERActivateKeyboardLayoutinwin32apiinteger; hkl,stringflagaddi localmaxnumber,handlebuf,i,j,temp1 publicimename,dechandle,imenumber maxnumber=15 handlebuf=space(60)
4、&&按15个输入法设置,每个占4个字符 clea &&获得系统已安装的输入法数及句柄 imenumber=GetKeyboardLayoutList(maxnumber,@handlebuf) dimehexhandle[imenumber],dechandle[imenumber],imename[imenumber] forj=1toimenumber temp1=′′ fori=4to1step-1 temp1=temp1+this.producehandle(asc(substr(handlebuf,i+(j-1)*4,
5、1))) endfor hexhandle[j]=temp1 dechandle[j]=this.hextodec(temp1) imename1=space(29) ImmGetdescription(dechandle[j],@imename1,29) ifalltrim(imename1)==′′ imename[j]=″英语(美国)″ else imename[j]=alltrim(imename1) endif endfor 4.为类ime添加“producehandle”方法,在此方法中写入以下程序: pa
6、raascvalue ifascvalue〈16 ifascvalue〈10 hexvalue=′0′+alltrim(str(ascvalue)) else hexvalue=′0′+alltrim(chr(55+ascvalue)) endif else highdec=int(ascvalue/16) lowdec=mod(ascvalue,16) ifhighdec〈10 highhex=alltrim(str(highdec)) else highhex=alltrim(chr(55+highdec)) e
7、ndif iflowdec〈10 lowhex=alltrim(str(lowdec)) else lowhex=alltrim(chr(55+lowdec)) endif hexvalue=highhex+lowhex endif returnhexvalue 5.为类ime再添加新方法″hextodec″,此方法是类ime内部使用的函数,用于将十六进制的字符串转换为所对应的十进制数,其代码如下: parastrings privatereturn1,return2,counter,length,flag,strings
8、 length=len(strings) flag=substr(strings,1,1) ifflag〉=′8′ temp2=′′ ret