PostMessage我这个什么地方错了?
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_RETURN = &HD
Private Sub Command2_Click()
Dim hdl As Long
hdl = GetForegroundWindow ' hdl is the handle to the foreground window
'AppActivate ( "1.txt - 记事本 ")
PostMessage hdl, VK_RETURN, 0, 0
End Sub
我这个什么地方错了?
[解决办法]
你在PostMessage之前要先连接到目标队列的输入线程
AttachThreadInput API
[解决办法]
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 WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_CHAR = &H102
'Text3.Text 的数字是目标文本框的HWND
Call PostMessage(CLng(Text3.Text), WM_KEYDOWN, 13, 0)
绝对可以的。