VB向其他窗口发送按键为什么没有反应
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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
Const WM_CLOSE = &H10
Const WM_KEYDOWN = &H100
Const VK_RETURN = &HD
Const MsgTitle As String = "Test Message"
Dim testhwnd&
Private Sub Command1_Click()
Timer1.Interval = 3000: Timer1.Enabled = True
Call MessageBox(Me.hwnd, "若您不回应的话, 3 秒后本对话匡将自动关闭", MsgTitle, 64)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
testhwnd = FindWindow(vbNullString, MsgTitle)
PostMessage testhwnd, WM_KEYDOWN, VK_RETURN0, 0
End Sub
--------------------编程问答--------------------
这个代码有错吗?怎么我用PostMessage和SendMessage试过都没有作用呢?(对其他窗口没有作用,高手指教一下谢谢!)
--------------------编程问答--------------------
VK_RETURN0常数名多了个0
Private Sub Timer1_Timer()
testhwnd = FindWindow(vbNullString, MsgTitle)
PostMessage testhwnd, WM_KEYDOWN, VK_RETURN, 0
End Sub
--------------------编程问答--------------------
补充:VB , 基础类