# Re: 拆出中文字的字码

Posted by cww on February 26, 1998 at 00:18:28:

In Reply to: 拆出中文字的字码 posted by 阿晴 on February 25, 1998 at 06:09:34:

我试过这类的function，可以把某个中文字拆出它的字根，若为注音，可
以拆出其拼音及破音字的拼法，如： "的" 大易输入可传回"竹日马点"
注音可传回 "ㄉ　ㄜ˙" "ㄉㄧ　ˊ" "ㄉㄧ　ˋ”，不过却没有找到
直接Mapping到英文的作法(如:注音"的" --> dk7 )，不过最少可以建表
去Mapping

Private Sub Command1_Click()
Dim hkb As Long
hkb = GetKeyboardLayout(0)
Text2.Text = ImeQueryComp(hkb, Text1.Text, 1)
End Sub

'hKB :keyboard handle, cChinaWord:中文字, nth :第n个拆字法（字根组合),由1起算
Public Function ImeQueryComp(ByVal hkb As Long, ByVal bChinaWord As String, Optional nth As Variant) As String
Dim iMaxkey As Long, dwGCL As Long
Dim tCandidate As CANDIDATELIST
Dim iStart As Long, i As Long, j As Long, icount As Integer
Dim dwBuff() As Byte
Dim result() As Byte

If IsMissing(nth) Then
nth = 1
End If

ImeQueryComp = ""
iMaxkey = ImmEscape(hkb, 0, IME_ESC_MAX_KEY, vbNullString)

If iMaxkey 0 Then
If nth > icount Then '没有nth个的candidate
Exit Function
End If
iStart = dwBuff(24 + (nth - 1) * 4)
j = 0
ReDim result(iMaxkey * 2)
For i = iStart To iStart + iMaxkey * 2
result(j) = dwBuff(i)
j = j + 1
Next i
ImeQueryComp = StrConv(result, vbUnicode)
End If
End Function

Follow Ups: