vb sendmessage 发送text内容乱码
我用sendmessage 发送text里面的内容a17 怎么发送到其他窗口变成了a!&,
[解决办法]
对于楼主的要求,可以这样写
Option Explicit
Private Const WM_CHAR = &H102
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'将一个字符串通过PostMessage传送出去
Private Sub subPostString(ByVal lngHandle As Long, ByVal strP As String)
Dim intP As Integer
Dim intK As Integer
Dim lngAsc As Long
Dim lngP As Long
Dim strT As String
On Error GoTo errSub
For intP = 0 To Len(strP) - 1
strT = Mid(strP, intP + 1, 1)
If Asc(strT) <= 0 Then
lngAsc = AscW(StrConv(strT, 128))
If lngAsc < 0 Then
lngAsc = lngAsc + 65536 '2^16
End If
Else
lngAsc = Asc(strT)
End If
lngP = PostMessage(lngHandle, WM_CHAR, lngAsc, 0)
Next intP
Exit Sub
errSub:
End Sub
Private Sub Command1_Click()
Call subPostString(Text1.hwnd, "a17") '将字符串发送给输入文本框
End Sub