对RichEdit20控件发送WM_GETTEXT得到的是乱码?怎么解决呀

对RichEdit20控件发送WM_GETTEXT得到的是乱码?如何解决呀xhwnd是一个RichEdit20A控件的句柄iSendMessage(

对RichEdit20控件发送WM_GETTEXT得到的是乱码?如何解决呀
xhwnd是一个RichEdit20A控件的句柄

        i   =   SendMessage(xhwnd,   WM_GETTEXTLENGTH,   0,   ByVal   0&)
       
        Dim   buff()   As   Byte
        ReDim   buff(i)
        i   =   SendMessage(xhwnd,   WM_GETTEXT,   i   +   1,   buff(0))
     
        MsgBox   StrConv(buff,   vbUnicode)


不知道为什么?我确保   xhwnd是正确的
是不是要对返回的数据做适当处理呀?

[解决办法]
试试EM_GETTEXTEX 消息
[解决办法]
This is impossible mission!
http://community.csdn.net/Expert/TopicView3.asp?id=5648720
http://community.csdn.net/Expert/TopicView3.asp?id=5646744

重申:
(不考虑Win9x,因为更复杂)对于XP英文/中文系统,如果你的Non-Unicode设定是English, SendMessage 根本就不可能得到中文.但如果Non-Unicode设定是Chinese (PRC),上面的编码可以取得中文。原因在于SendMessage有经过Unicode到ANSI/DBCS的几次转换,造成Unicode的丢失。

我挣扎多年都没成功!!!不信你们将你的non-Unicode设定为English!!!
Control Panel --> Language and Region options --> Advance Tab ---> English as non-Unicode

'RichEdit GetLine Function From VBAdvisor
Public Type TEXTRANGE
chrg As CHARRANGE
lpstrText As Long
End Type

Public Function GetLineText(Byval hWnd as long,ByVal LineNum As Long) As String
Dim LineCount As Long
Dim lc As Long, j As Long
Dim charFrom As Long
Dim charEnd As Long
Dim CR As CHARRANGE
Dim TR As TEXTRANGE

LineCount = SendMessageLong(hWnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
If LineNum > LineCount Then
GetLineText = vbNullString
Exit Function
End If
charFrom = SendMessageLong(hWnd, EM_LINEINDEX, LineNum, ByVal 0&)
lc = SendMessageLong(hWnd, EM_LINELENGTH, ByVal charFrom, ByVal 0&)
If lc = 0 Then
GetLineText = vbNullString
Exit Function
End If

GetLineText = TextInRange(charFrom, charFrom + lc)

End Function

Public sub TextInRange(Byval hWnd as long,ByVal lStart As Long, ByVal lEnd As Long)

Dim TR As TEXTRANGE
Dim sText As String
Dim lR As Long
Dim B() As Byte

TR.chrg.cpMin = lStart
TR.chrg.cpMax = lEnd

' VB won 't do the terminating null for you!
sText = String$(lEnd - lStart + 1, 0)
B = sText
ReDim Preserve B(0 To (lEnd - lStart + 1)) As Byte
TR.lpstrText = VarPtr(B(0))

lR = SendMessageLong(hWnd, EM_GETTEXTRANGE, 0, VarPtr(TR))

If (lR > 0) Then
' lstrlen assumes that lpString is a NULL-terminated string !!!
CopyMemory ByVal sText, ByVal TR.lpstrText, lR
TextInRange = Left$(sText, lR)
End If

End Sub

'TextBox GetLine Function From VBAdvisor
Public Function GetLine(Byval hWnd As long,ByVal whichLine As Long) As String

Dim nLen As Long, bArr() As Byte, bArr2() As Byte, lReturn As Long

lReturn = SendMessage(hWnd , EM_LINEINDEX, whichLine, ByVal 0&)

nLen = SendMessage(hWnd , EM_LINELENGTH, lReturn, ByVal 0&)

If nLen > 0 Then
ReDim bArr(2 * nLen + 1) As Byte, bArr2(2 * nLen - 1) As Byte
Call CopyMemory(bArr(0), 2 * nLen, 2)
Call SendMessage(hWnd , EM_GETLINE, whichLine, bArr(0))
Call CopyMemory(bArr2(0), bArr(0), 2 * nLen)

GetLine = String$(UBound(bArr2) + 1, vbNullChar)


CopyMemory ByVal GetLineString, bArr2(0), UBound(bArr) + 1

Else
GetLine = vbNullString
End If

End Function
[解决办法]
帮你顶一下
[解决办法]
......................................
[解决办法]
英文的没试过,不过中文下这个函数获取QQ的RichEdit没问题

Public Function GetWindowContent(hwnd As Long) As String
Dim sBuffer As String
Dim lLength As Long
lLength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, ByVal 0&)
sBuffer = String(lLength + 1, 0)
SendMessage hwnd, WM_GETTEXT, lLength + 1, ByVal sBuffer
GetWindowContent = Left(sBuffer,instr(1,sBuffer,chr(0)))
End Function