level 1
黑化肥会发挥灰
楼主
发送方
Public Class Form1
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Public Enum 传递字符串
开始 = 4141
结束 = 5151
传输中 = 6161
End Enum
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hwnd As Integer = FindWindow(vbNullString, "接受消息的窗口")
Dim str = "这是一个字符串"
给目标程序发送字符串(hwnd, str)
End Sub
Sub 给目标程序发送字符串(hwnd As Integer, str As String)
SendMessage(hwnd, 传递字符串.开始, 0, 0)
For i = 1 To Len(str)
SendMessage(hwnd, 传递字符串.传输中, 0, Asc(Mid(str, i, 1)))
Next
SendMessage(hwnd, 传递字符串.结束, 0, 0)
End Sub
End Class
接收方
Public Class Form1
Public 接受到的字符串 As String
Public Enum 传递字符串
开始 = 4141
结束 = 5151
传输中 = 6161
End Enum
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 传递字符串.开始 Then
接受到的字符串 = ""
ElseIf m.Msg = 传递字符串.传输中 Then
接受到的字符串 = 接受到的字符串 & Chr(m.LParam.ToInt32)
ElseIf m.Msg = 传递字符串.结束 Then
MsgBox(接受到的字符串)
End If
MyBase.WndProc(m)
End Sub
End Class
2016年08月03日 14点08分
1
Public Class Form1
Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Public Enum 传递字符串
开始 = 4141
结束 = 5151
传输中 = 6161
End Enum
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hwnd As Integer = FindWindow(vbNullString, "接受消息的窗口")
Dim str = "这是一个字符串"
给目标程序发送字符串(hwnd, str)
End Sub
Sub 给目标程序发送字符串(hwnd As Integer, str As String)
SendMessage(hwnd, 传递字符串.开始, 0, 0)
For i = 1 To Len(str)
SendMessage(hwnd, 传递字符串.传输中, 0, Asc(Mid(str, i, 1)))
Next
SendMessage(hwnd, 传递字符串.结束, 0, 0)
End Sub
End Class
接收方
Public Class Form1
Public 接受到的字符串 As String
Public Enum 传递字符串
开始 = 4141
结束 = 5151
传输中 = 6161
End Enum
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 传递字符串.开始 Then
接受到的字符串 = ""
ElseIf m.Msg = 传递字符串.传输中 Then
接受到的字符串 = 接受到的字符串 & Chr(m.LParam.ToInt32)
ElseIf m.Msg = 传递字符串.结束 Then
MsgBox(接受到的字符串)
End If
MyBase.WndProc(m)
End Sub
End Class