1

I try to get the text from a richtextbox control in vb6. However, the unicode text this is not working.

text1=richtextbox1.text

this gave me "????"

Can anybody help me?


This Code does not worked. I try to run it with this declarations:

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

And I dont know about :

EM_GETTEXTLENGTHEX , EM_GETTEXTEX

Please send complete Code. (with all declares)

Deanna
  • 23,876
  • 7
  • 71
  • 156
mahdi
  • 11
  • 3
  • 1
    According to [this MSDN Blog](http://blogs.msdn.com/b/michkap/archive/2005/08/21/454340.aspx) the VB6 RichTextBox control doesn't actually support Unicode. It goes on to suggest dropping $399 on suite of 3rd party controls, but IMO downloading VB.NET Express Edition for free would probably be a better option. – Nathan Andrew Mullenax Sep 07 '12 at 19:18
  • See also this question: [what's the best option to display Unicode text in VB6](http://stackoverflow.com/questions/540361/whats-the-best-option-to-display-unicode-text-hebrew-etc-in-vb6) – MarkJ Sep 08 '12 at 18:13
  • @mahdi: Please don;t replace the question with a "thank you" notice. This site is about helping other people with similar issues and removing the question makes it useless. If you want to follow up, please comments on the accepted answer and click the green tip to the left. – Deanna Sep 12 '12 at 15:37

1 Answers1

1

Pretty easy really. Here are the bare bones without the required Declare, Const, etc. declarations:

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
Cibo FATA8
  • 103
  • 6
Bob77
  • 13,167
  • 1
  • 29
  • 37