怎样利用SendMessage向webbrowser控件里面的网页文本框输入文本

2024-12-15 14:30:51
推荐回答(1个)
回答1:

Public Class Form1

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_CHAR as Integer= &H102

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = "hello !中华人民共和国"
Dim bytes() As Byte = System.Text.Encoding.Default.GetBytes(str)
For Each b As Byte In bytes
PostMessage(Me.TextBox1.Handle, WM_CHAR, b, 0)
Next
End Sub
End Class

上面API声明中的LONG需要全部改为Integer
WM_CHAR是可以输入中文的。