我用sendmessage 发送text里面的内容a17 怎么发送到其他窗口变成了a!&,

解决方案 »

  1.   


    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
    这是我的一个发送字符串的例子,用的是PostMessage
    关于PostMessage和SendMessage两个函数,实际上,两个函数功能相似,只是消息处理机制不同,在很多场合下都可以互换。
      

  2.   

    SendMessage hWnd, WM_SETTEXT, 0, ByVal "a17 "
      

  3.   

    对于楼主的要求,可以这样写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