1

我尝试从 vb6 中的richtextbox 控件中获取文本。但是,这不起作用的 unicode 文本。

text1=richtextbox1.text

这给了我"????"

有谁能够帮我?


此代码不起作用。我尝试使用以下声明运行它:

Const GTL_USECRLF = 1
Const GTL_PRECISE = 2
Const GTL_NUMCHARS = 8
Const CP_UNICODE = 1200
Const GT_USECRLF = 1
Private Type GETTEXTEX
    cb As Long
    flags As Long
    codepage As Integer
    lpDefaultChar As String
    lpUsedDefChar As Boolean
End Type
Private Type GETTEXTLENGTHEX
    flags As Long          ' /* flags (see GTL_XXX defines)              */
    codepage As Long       ' /* code page for translation (CP_ACP for default,
                            '1200 for Unicode                         */
End Type

我不知道:

EM_GETTEXTLENGTHEX , EM_GETTEXTEX

请发送完整的代码。(所有声明)

4

1 回答 1

1

真的很容易。以下是没有 required , 等声明的基本Declare框架Const

public Declare Function SendMessageWLng Lib "user32" Alias "SendMessageW" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_USER = &H400
Public Const EM_GETSCROLLPOS = WM_USER + 221
Public Const EM_SETSCROLLPOS = WM_USER + 222

Public Const CP_UNICODE = 1200&
Public Const GT_USECRLF = 1&
Public Const GTL_USECRLF = 1&
Public Const GTL_PRECISE = 2&
Public Const GTL_NUMCHARS = 8&

Public Const EM_GETTEXTEX = WM_USER + 94
Public Const EM_GETTEXTLENGTHEX = WM_USER + 95

    Public Function RTBReadUnicode(ByVal RTB As RichTextLib.RichTextBox) As String
        'Reads Text from RichTextBox as Unicode text on a system with Rich Edit 3.0
        '(Windows Me, Windows 2000, or later).
        Dim gtlUnicode As GETTEXTLENGTHEX
        Dim gtUnicode As GETTEXTEX
        Dim lngChars As Long
    
        With gtlUnicode
            .flags = GTL_USECRLF Or GTL_PRECISE Or GTL_NUMCHARS
            .codepage = CP_UNICODE
        End With
        lngChars = SendMessageWLng(RTB.hWnd, EM_GETTEXTLENGTHEX, VarPtr(gtlUnicode), 0)
    
        With gtUnicode
            .cb = (lngChars + 1) * 2
            .flags = GT_USECRLF
            .codepage = CP_UNICODE
        End With
        RTBReadUnicode = String$(lngChars, 0)
        SendMessageWLng RTB.hWnd, EM_GETTEXTEX, VarPtr(gtUnicode), StrPtr(RTBReadUnicode)
    End Function
于 2012-09-08T03:32:30.393 回答