收藏 分销(赏)

PB全角和半角字符的转换解决方案.doc

上传人:仙人****88 文档编号:9449912 上传时间:2025-03-26 格式:DOC 页数:5 大小:35KB 下载积分:10 金币
下载 相关 举报
PB全角和半角字符的转换解决方案.doc_第1页
第1页 / 共5页
PB全角和半角字符的转换解决方案.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
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) library "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才行;
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服