我想在表单里添加一个按钮
功能 是选择输入法 五笔 智能 英文之类的
这个按钮怎么设计啊
江南红雨翻译的方法,你试一下吧,应该可以
* 程序: 枚举所有输入法供用户选择
* 设计: 红雨
* 时间: 2001年11月09日
*--------------------------------
Clea
oform=NEWOBJECT("红雨表单")
oform.SHOW
Read EVENTS
Retu
*--------------------------------
Define CLASS 红雨表单 AS form
ShowWindow = 2
AutoCenter = .T.
AlwaysOnTop = .T.
BorderStyle = 0
Caption = "汉字输入法选择类示例表单 - 红雨"
WindowType = 1
BackColor = RGB(0,255,128)
Picture = ""
Add OBJECT 编辑框 AS TextBox WITH ;
top = 70, left = 10, width = thisform.width-20, height = thisform.height-80, Name = "编辑框", Value = "中文输入框"
Add OBJECT 文本框 AS TextBox WITH ;
top = 40, left = 10, width = thisform.width-20, Name = "文本框", ImeMode = 2, Value = "西文输入框"
Add OBJECT 输入法 AS hyimmg WITH ;
top = 10, left = 10, width = thisform.width-20, Name = "输入法"
Procedure 编辑框.GotFocus
Thisform.输入法.ActiveIme()
Endproc
Procedure Unload
Clear Dlls
Clear EVENTS
Endproc
Enddefine
**************************************************
*-- Class: hyimmg
*-- ParentClass: container
*-- BaseClass: container
*
Define CLASS hyimmg AS container
Width = 145
Height = 21
SpecialEffect = 1
imehandle = 67699721
Name = "hyimmg"
Dimension imename[1,1]
Dimension dechandle[1,1]
Dimension ehexhandle[1,1]
Add OBJECT label1 AS label WITH ;
BackStyle = 0, ;
Caption = "输入法", ;
Enabled = .F., ;
Height = 16, ;
Left = 4, ;
Top = 4, ;
Width = 38, ;
DisabledForeColor = RGB(0,0,160), ;
Name = "Label1"
Add OBJECT combo1 AS combobox WITH ;
RowSourceType = 5, ;
RowSource = "This.parent.imename", ;
DisplayValue = 1, ;
Height = 19, ;
Left = 44, ;
Style = 2, ;
Top = 1, ;
Width = 100, ;
Name = "Combo1"
Procedure producehandle
Para ascvalue
* 此程序段用于将十进制形式的ASCII码值转换为十六进制形式的字符串
If ascvalue<16
If ascvalue<10
hexvalue="0"+alltrim(str(ascvalue))
Else
hexvalue="0"+alltrim(chr(55+ascvalue))
Endif
Else
highdec=int(ascvalue/16)
lowdec=mod(ascvalue,16)
If highdec<10
highhex=alltrim(str(highdec))
Else
highhex=alltrim(chr(55+highdec))
Endif
If lowdec<10
lowhex=alltrim(str(lowdec))
Else
lowhex=alltrim(chr(55+lowdec))
Endif
hexvalue=highhex+lowhex
Endif
Return hexvalue
Endproc
Procedure hextodec
Para strings
* 此程序段用于将十六进制的字符串转换为所对应的十进制数
Private return1,return2,counter,length,flag,strings
Length=len(strings)
flag=substr(strings,1,1)
If flag>="8" &&若最高位为大于等于8的数字,则其对应的数字为负数
temp2=""
return2=""
i1=1
For i1=1 to length &&对各位进行取反操作
temp1=substr(strings,i1,1)
If temp1>="9"
temp2=chr(5-(asc(temp1)-65)+48)
Else
If temp1>"5"
temp2=chr(15-(asc(temp1)-48)+48)
Else
temp2=chr(15-(asc(temp1)-48)+55)
Endif
Endif
return2=return2+temp2 &&return2为生成的反码
Endfor
strings=return2
Endif
return1=0
I=1
For i=1 to length &&将十六进制数字符串转换为十进制数
temp1=substr(strings,i,1)
If temp1>"9"
temp2=asc(temp1)-65+10
Else
temp2=asc(temp1)-48
Endif
return1=temp2*16^(length-i)+return1
Endfor
If flag>="8" &&若为负数,对转换的十进制数加1,取负
handle=int(0-(return1+1))
Else
handle=int(return1)
Endif
Return handle
Endproc
Procedure activeime
* 为程序提供打开选定输入法的接口,其代码如下:
= ActivateKeyboardLayout(this.imehandle,"KLF_ACTIVATE")
Endproc
Procedure Resize
With this
.height = 21
.Combo1.width = .width-.Combo1.left-2
Endwith
Endproc
Procedure Init
Declare INTEGER GetKeyboardLayoutList in win32api integer nbuff, string @pointer1
Declare INTEGER ActivateKeyboardLayout in win32api integer hkl, string flag
Declare INTEGER ImmGetDescription in imm32 integer hkl, string @lpsz, integer nnumber
With this
.height = 21
.Combo1.width = .width-.Combo1.left-2
Local maxnumber,handlebuf,i,j,temp1
maxnumber = 15
handlebuf = space(60)
* 按15个输入法设置,每个占4个字符
* 获得系统已安装的输入法数及句柄
imenumber = GetKeyboardLayoutList(maxnumber,@handlebuf)
Dime .ehexhandle[imenumber], .dechandle[imenumber], .imename[imenumber]
?imenumber
For j=1 to imenumber
temp1=""
For i=4 to 1 step -1
* API函数GetKeyboardLayoutList返回的数据为ASCII字符
* 序列,4个为一组,每个字符的ASCII值的十六进制数相连
* 就是打开输入法的句柄
temp1=temp1 + .producehandle(asc(substr(handlebuf,i+(j-1)*4,1)))
Endfor
.ehexhandle[j] = temp1
.dechandle[j] = .hextodec(temp1)
imenamett = space(29)
* ImmGetdescription函数需要十进制形式的句柄
= ImmGetdescription(.dechandle[j], @imenamett, 29)
If alltrim(imenamett)==""
.imename[j] = "英语(美国)"
Else
.imename[j] = alltrim(imenamett)
Endif
?.imename[j]
Endfor
.combo1.RowSource = "This.parent.imename"
Endwith
Endproc
Procedure combo1.InteractiveChange
Private selindex
selindex = this.listindex
This.parent.imehandle = this.parent.dechandle[selindex]
This.parent.ActiveIme()
Endproc
Enddefine
*
*-- EndDefine: hyimmg