VB6用API實現繁體簡體轉換

2021-06-08 16:03:48 字數 2844 閱讀 3174

private declare function lcmapstring lib "kernel32" alias "lcmapstringa" ( _

byval locale as long, _

byval dwmapflags as long, _

byval lpsrcstr as string, _

byval cchsrc as long, _

byval lpdeststr as string, _

byval cchdest as long) as long

private declare function lstrlen lib "kernel32" alias "lstrlena" (byval lpstring as string) as long

private declare function getsystemdefaultlcid lib "kernel32 " () as long

private function getoslcid() as integer

dim syslcid     as long

syslcid = getsystemdefaultlcid

'&h409(us-英文)&h809(gb-英文)     &hc09(au-英文)   &h1009(ca-英文)

'&h004(zh-中文)&h404(tw-big5)&h804(cn-gbk/gb)&hc04(hk-big5)   &h1004(sg-gbk)

'&h804=2052   &h404=1028   &h409=1033   &h809=2057

if syslcid = &h804 or syslcid = &h4 or syslcid = &h1004 then

getoslcid = 1       '中文簡體

elseif syslcid = &h404 or syslcid = &hc04 then

getoslcid = 2       '中文繁體

elseif syslcid mod 16 = 9 then

getoslcid = 0       '(英文)

else

getoslcid = 0

end if

end function

private function convertchinesesimplifiedortraditional(byval strsrc as string, byval bsimplified as boolean) as string

dim lngsrclen as long

dim strbuffer as string

lngsrclen = lstrlen(strsrc)

if lngsrclen = 0 then exit function

strbuffer = space(lngsrclen)

if bsimplified then '轉換為簡體

lcmapstring &h804, &h2000000, strsrc, lngsrclen, strbuffer, lngsrclen

else

lcmapstring &h804, &h4000000, strsrc, lngsrclen, strbuffer, lngsrclen

end if

convertchinesesimplifiedortraditional = strbuffer

end function

'******   簡繁體互換   gb--> unicode--> big5  

or   big5--> unicode--> gb     *****************

'引數sstr為需要轉換的文字

'引數iconver為要轉化的型別,為1時表示繁體到簡體的轉換,為2時表示簡體到繁體的轉換

function   gbbig5(sstr   as   string,   iconver   as   integer)   as   string

on   error   resume   next

dim   str

if   iconver   =   1   then   'big5--> gb

str   =   strconv(sstr,   vbfromunicode,   &h804)

gbbig5   =   strconv(str,   vbunicode,   &h404)

elseif   iconver   =   2   then   'gb--> big5

str   =   strconv(sstr,   vbfromunicode,   &h404)

gbbig5   =   strconv(str,   vbunicode,   &h804)

end   if

end   function

這是vb6的函式,用法如下:

strconv(string,   conversion,   lcid)   `vb6

string呢,就是預轉換的字串了(提示一下,也可以使用byte陣列)。

conversion:   是乙個整數,只決定轉換方式,vb裡定義了一些常量,如vbfromunicode、vbunicode等等,這些不用我解釋大家應該也明白了吧。

lcid:哈,這可是vb6新加入的引數了,長整數,   可以指定編碼方式,   如&h404,即big5碼,   &h804即gbk碼,合理運用這個引數,就可以寫出乙個非常簡單的內碼轉換工具!

VB6用API實現繁體簡體轉換

由於正好需要乙個繁體轉簡體的事情,弄這個函式將就用一下了。private declare function lcmapstring lib kernel32 alias lcmapstringa byval locale as long,byval dwmapflags as long,byval ...

Vb 實現簡體轉繁體

lcmapstring 映像字串 private declare function lcmapstring lib kernel32 alias lcmapstringa byval locale as long,byval dwmapflags as long,byval lpsrcstr as ...

API實現快速轉換簡體字與繁體字

private declare function lcmapstring lib kernel32 alias lcmapstringa byval locale as long,byval dwmapflags as long,byval lpsrcstr as string,byval cchs...