如何调用输入法,得到汉字的拼音
来源:互联网 发布:手机手写软件 编辑:程序博客网 时间:2024/04/29 06:12
' 由汉字获取拼音,需要安装微软拼音输入法
Option Explicit
Private Const IME_ESC_MAX_KEY = &H1005
Private Const IME_ESC_IME_NAME = &H1006
Private Const GCL_REVERSECONVERSION = &H2
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As _
Long) As Long
Private Declare Function ImmEscape Lib "imm32.dll" Alias "ImmEscapeA" (ByVal hkl As Long, ByVal _
himc As Long, ByVal un As Long, lpv As Any) As Long
Private Declare Function ImmGetConversionList Lib "imm32.dll" Alias "ImmGetConversionListA" _
(ByVal hkl As Long, ByVal himc As Long, ByVal lpsz As String, lpCandidateList As Any, ByVal _
dwBufLen As Long, ByVal uFlag As Long) As Long
Private Declare Function IsDBCSLeadByte Lib "kernel32" (ByVal bTestChar As Byte) As Long
'微软拼音输入法
Public Function GetChineseSpell(Chinese As String, Optional Delimiter As String = " ", Optional IMEName As String = "微软拼音输入法", Optional BufferSize As Long = 255) As String
If VBA.Len(VBA.Trim(Chinese)) > 0 Then
Dim i As Long
Dim s As String
s = VBA.Space(BufferSize)
Dim IMEInstalled As Boolean
Dim j As Long
Dim a() As Long
ReDim a(BufferSize) As Long
j = GetKeyboardLayoutList(BufferSize, a(LBound(a)))
For i = LBound(a) To LBound(a) + j - 1
If ImmEscape(a(i), 0, IME_ESC_IME_NAME, ByVal s) Then
If VBA.Trim(IMEName) = VBA.Replace(VBA.Trim(s), VBA.Chr(0), "") Then
IMEInstalled = True
Exit For
End If
End If
Next i
If IMEInstalled Then
'Stop
Chinese = VBA.Trim(Chinese)
Dim sChar As String
Dim Buffer0() As Byte
'Dim Buffer() As Byte
Dim bBuffer0() As Byte
Dim bBuffer() As Byte
Dim k As Long
Dim l As Long
Dim m As Long
For j = 0 To VBA.Len(Chinese) - 1
sChar = VBA.Mid(Chinese, j + 1, 1)
Buffer0 = VBA.StrConv(sChar, vbFromUnicode)
If IsDBCSLeadByte(Buffer0(0)) Then
k = ImmEscape(a(i), 0, IME_ESC_MAX_KEY, Null)
If k Then
l = ImmGetConversionList(a(i), 0, sChar, 0, 0, GCL_REVERSECONVERSION)
If l Then
s = VBA.Space(BufferSize)
If ImmGetConversionList(a(i), 0, sChar, ByVal s, l, GCL_REVERSECONVERSION) Then
bBuffer0 = VBA.StrConv(s, vbFromUnicode)
ReDim bBuffer(k * 2 - 1)
For m = bBuffer0(24) To bBuffer0(24) + k * 2 - 1
bBuffer(m - bBuffer0(24)) = bBuffer0(m)
Next m
sChar = VBA.Trim(VBA.StrConv(bBuffer, vbUnicode))
If VBA.InStr(sChar, vbNullChar) Then
sChar = VBA.Trim(VBA.Left(sChar, VBA.InStr(sChar, vbNullChar) - 1))
End If
sChar = VBA.Left(sChar, VBA.Len(sChar) - 1) & VBA.IIf(j < VBA.Len(Chinese) - 1, Delimiter, "")
End If
End If
End If
End If
GetChineseSpell = GetChineseSpell & sChar
Next j
Else
End If
End If
End Function
Private Sub Command1_Click()
VBA.MsgBox GetChineseSpell("接分")
End Sub
- 如何调用输入法,得到汉字的拼音
- 如何得到汉字的拼音首字母呢?
- 得到汉字的拼音
- 得到汉字的拼音首字母
- 得到汉字的拼音码
- 如何根据汉字得到响应的拼音(转)
- c#中如何得到汉字的拼音首字母
- 根据汉字得到相应的拼音
- 自动得到汉字拼音首字母的代码
- 得到汉字拼音的原码
- 输入法汉字拼音码表
- 如何获取汉字的拼音
- 如何得到汉字的首拼码
- python得到汉字拼音首字母
- Android输入汉字得到拼音
- Android输入汉字得到拼音
- 得到汉字拼音码-首字母
- 从全拼音中得到汉字拼音
- MyEclipse启动jre和工程jre冲突的解决方法
- 关于RuntimeException
- yield方法和join方法
- FreeTextBox使用详解
- Asp.net连接SQL Server2000数据库例程详解:
- 如何调用输入法,得到汉字的拼音
- Seven JavaScript Techniques You Should Be Using Today
- SQL安装挂起,解决方法
- SQL SERVER数据库开发之存储过程应用
- c++学习杂记(4)
- 数据字典的基本原理如何?
- 梦想中体会快乐
- 数据字典多个实例
- 嵌入式项目Makefile设计的一般方法