关于用sendmessage发送模拟按键的问题。
代码如下:
Private Sub Command1_Click()
Dim str As String, data() As Byte, i As Long
str = "ABC你好。abc "
i = 0
data = StrConv(str, vbFromUnicode)
While i <= UBound(data)
If data(i) < 128 Then
SendMessage Text1.hwnd, WM_CHAR, data(i), 0&
i = i + 1
Else
SendMessage Text1.hwnd, WM_CHAR, data(i), 0&
SendMessage Text1.hwnd, WM_CHAR, data(i + 1), 0&
i = i + 2
End If
Wend
End Sub
可运行后text1里不直的在输入A,只能强行关掉。
用WM_KEYDOWN和WM_KEYUP则text1没有任何值。
系统是win 2003 + vb6
[解决办法]
用sendKeys不好吗?
或者用API:keyb_event()
[解决办法]
SendMessage Text1.hwnd, WM_SETTEXT, 0, ByVal "ABC你好。abc "
[解决办法]
你可以试试PostMessage(下面的代码可以往 "计算器 "发送一个数字3按下的消息)
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
Private Const VK_H = 51
Private Const WM_KEYDOWN = &H100
Private Sub cmdPost_Click()
Dim hw&
hw& = FindWindow(vbNullString, "Calculator ")
If hw& = 0 Then
MsgBox "No program found!! "
Exit Sub
End If
PostMessage hw&, WM_KEYDOWN, VK_H, 0
End Sub
[解决办法]
http://www.m5home.com/blog/blogview.asp?logID=197
这是我前几天在网上找到的一个模块做成的网页星号查看器,就是使用的这招
里面有个函数,可以根据句柄取得IHTMLDocument对象接口
有了这个接口,你随便做什么都可以,嘿嘿