Scintilla GETTEXTRANGE 获取中文字符

Private Type CHARRANGE 'cr
    cpMin As Long
    cpMax As Long
End Type
Private Type TEXTRANGE
    chrg As CHARRANGE
    lpstrText As Long '这里一定要定义为Long不要定义为String
End Type
'拦截窗口的消息
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_NOTIFY Then
        Dim ns As NMHDR
        CopyMemory ns, ByVal lParam, Len(ns) '目标,源,大小-字节
        If ns.hwndFrom = SciLexerHwnd Then
            If ns.code = SCN_CHARADDED Then
                Dim dqpoint As Long
                Dim startint As Long
                Dim endint As Long
                Dim tr As TEXTRANGE
                Dim B() As Byte  'tr结构最后一个用这个方法引用一个数组的开头位置
                dqpoint = SendMessage(SciLexerHwnd, SCI_GETCURRENTPOS, 0, 0) '取得当前位置
                startint = SendMessage(SciLexerHwnd, SCI_WORDSTARTPOSITION, dqpoint - 1, False) '//当前单词起始位置
                endint = SendMessage(SciLexerHwnd, SCI_WORDENDPOSITION, dqpoint - 1, 0) '//当前单词终止位置
                tr.chrg.cpMax = endint
                tr.chrg.cpMin = startint
                ReDim Preserve B(0 To (endint - startint + 1)) As Byte
                tr.lpstrText = VarPtr(B(0))
                lR = SendMessagesc(SciLexerHwnd, SCI_GETTEXTRANGE, 0, tr) '获取
                If (lR > 0) Then
                    Debug.Print UTF8ToUTF16(B)
                End If
            End If
        End If
    End If
    WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
End Function

Scintilla GETTEXTRANGE 获取中文字符


本站如无特别说明即为原创,转而告知:(http://iwonmo.com/archives/9.html)

标签: scintilla, gettextrange, 中文字符

添加新评论