我尝试从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
请发送完整的代码。 (所有声明)
答案 0 :(得分:1)
真的很容易。以下是没有所需Declare
,Const
等声明的裸骨:
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