VB Sendmessage问题
Private Declare Function SendMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_F1 = &H70
Const VK_F2 = &H71
Const VK_F3 = &H72
Const VK_F4 = &H73
Const VK_F5 = &H74
Const VK_A = &H41
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Shell "notepad.exe", 1
End Sub
Private Sub Command2_Click()
Dim hwd As Long
hwd = FindWindow(vbNullString, "无标题 - 记事本")
SendMessage hwd, WM_KEYDOWN, VK_F5, 0&
End Sub
Private Sub Form_Load()
Command1.Caption = "打开记事本"
Command2.Caption = "关闭记事本"
End Sub
该例子模拟按下F5有效
Private Declare Function SendMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const VK_F1 = &H70
Const VK_F2 = &H71
Const VK_F3 = &H72
Const VK_F4 = &H73
Const VK_F5 = &H74
Const VK_A = &H41
Const WM_CLOSE = &H10
Private Sub Command1_Click()
Shell "notepad.exe", 1
End Sub
Private Sub Command2_Click()
Dim hwd As Long
hwd = FindWindow(vbNullString, "无标题 - 记事本")
SendMessage hwd, WM_KEYDOWN, VK_A, 0&
End Sub
Private Sub Form_Load()
Command1.Caption = "打开记事本"
Command2.Caption = "关闭记事本"
End Sub
该例子模拟按下A无效,求解