|
|
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)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Check1_Click()
Call keybd_event(VK_shift, MapVirtualKey(VK_shift, 0), 0, 0) '只要按住shift就行
End Sub
Private Sub Form_Load()
Dim hwnd As Long
Dim pid As Long
Dim pHandle As Long
hwnd = FindWindow(vbNullString, "test")
If (hwnd = 0) Then
MsgBox "Window not found!"
Exit Sub
End If '得到handle
GetWindowThreadProcessId hwnd, pid '得到程序id
pHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '打开程序
If (pHandle = 0) Then
MsgBox "Couldn't get a process handle!" '这里出错了,就是得不到handle,我觉
Exit Sub '得没错呀,请给我看看啊
End If
End Sub
|
|