PB全角和半角字符的转换解决方案
PB中全角字符和半角字符之间的转换相关解决
方案
一 、 将字符串中的半角字符转换成全角字符 (函数)
//函数功能:将字符串中的半角字符转换成全角字符
//入口参数:in_str——准备进行转换的半角字符串 类型string
//返回值: 转换成功的全角字符串 类型
string
string c_return=""
long l0,l1,l2,l3,l4,i,c_leng,l_asc
i=1
c_leng=len(in_str)
do while i<=c_leng
l_asc=asc(in_str)
if l_asc<=128 then
if l_asc>=33 and l_asc<=126 then
l1=int((l_asc+41856)/(16*16*16))
l0=mod((l_asc+41856),(16*16*16))
l2=int(l0/(16*16))
l0=mod(l0,(16*16))
l3=int(l0/16)
l4=mod(l0,16)
c_return=c_return+char(l1*16+l2)+char(l3*16+l4)
else
c_return=c_return+left(in_str,1)
end if
in_str=replace(in_str,1,1,"")
i=i+1
else
c_return=c_return+left(in_str,2)
in_str=replace(in_str,1,2,"")
i=i+2
end if
loop
return c_return
二 、中英文输入法的切换及全角半角切换
切换中英文输入法及全角/半角,
问题描述:
如何切换中英文输入法及全角/半角、中英文字符等,
解决方案:
1、声明外部函数:
function boolean ImmSimulateHotKey (UnsignedLong hWnd,UnsignedLong
dwHotKeyID) library "IMM32.dll"
function unsignedlong GetKeyboardLayout (unsignedlong wLayout)library
"user32.dll"
function boolean ImmIsIME(unsignedLong hklKeyboardLayout)library
"IMM32.DLL"
2、在一个按钮里写:
long ll_hwnd
ll_hwnd = handle(sle_1)
If not ImmIsIME(GetKeyboardLayout(0)) Then
ImmSimulateHotKey(ll_hwnd,16)
End If
ImmSimulateHotKey(ll_hwnd,17)
3、测试:运行后在TEXT中先输入逗号,均为半角,再点按钮后再输入逗号,
均为全角
三 、自动切换输入法
比如把焦点切换到一个编辑框时,如何自动切换到你设置的输入法。也就是在程
序中如何控制从一个输入法切换到另一个切换
---------------------------------------------------------------
函数声明:
function boolean ImmSimulateHotKey (ULong hWnd, ULong dwHotKeyID) libr
ary "IMM32.dll"
function ulong GetKeyboardLayout(ulong dwLayout) LIBRARY "user32.dll"
function boolean ImmIsIME(uLong hklKeyboardLayout) library "IMM32.DLL"
脚本如下:
constant int IME_THotKey_IME_NonIME_Toggle=16 //112 使用16才可以自
动切换
ulong hklCurrent
ulong hnd
//切换到英文输入法
hklCurrent=GetKeyboardLayout(0)
if ImmIsIME(hklCurrent) then
hnd=Handle(parent)
ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle) end if
//切换到中文输入法
hklCurrent=GetKeyboardLayout(0)
if not ImmIsIME(hklCurrent) then
hnd=Handle(parent)
ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle) end if
---------------------------------------------------------------
int li_rownumber
string ls_rownumber
constant int IME_THotKey_IME_NonIME_Toggle=112 ulong hklCurrent
ulong hnd
li_rownumber=ldw_datawindow.getcolumn()
ls_rownumber=string(li_rownumber)
ls_rownumber=","+ls_rownumber+","
if match(ls_item_list,ls_rownumber) then
//切换到中文输入法
hklCurrent=GetKeyboardLayout(0)
if not ImmIsIME(hklCurrent) then
hnd=Handle(lw_window)
ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle)
end if
else
//切换到英文输入法
hklCurrent=GetKeyboardLayout(0)
if ImmIsIME(hklCurrent) then
hnd=Handle(lw_window)
ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle)
end if
end if
---------------------------------------------------------------
1先在Local extenal function定义下列API
Function function boolean ImmSimulateHotKey (UnsignedLong hWnd,UnsignedLong dwHotKeyID) library IMM32.dll
function unsignedlong GetKeyboardLayout (unsignedlong wLayout)library user32.dll
function boolean ImmIsIME(unsignedLong hklKeyboardLayout)library IMM32.DLL
如果是使用datawindow, 在itemchangedfocus event中
ulong hklKeyboardLayout
Choose Case dwo.name
Case chinese_text 需要中文输入的字段
hklKeyboardLayout=GetKeyboardLayout(0)
if not ImmIsIME(hklKeyboardLayout) then ImmSimulateHotKey(handle ( parent,112)
end if
Case Englist_text 英文输入字段
hklKeyboardLayout=GetKeyboardLayout(0)
if ImmIsIME(hklKeyboardLayout) then ImmSimulateHotKey(handle ( parent ),112)
end if
End Choose
在windows 编辑框中类似。
补充说明:这是网上很流行的例子,但是112好象不能切换,要改成16才行;