|
应该是撤销程序
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch 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, lParam As Any) As Long
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'Private Const WM_KEYDOWN = &H100 '按下键位
'Private Const WM_KEYUP = &H101 '弹起键位
'Private Const WM_CHAR = &H102 '清除键位
'Private Const WM_SYSKEYDOWN = &H104 '按下系统键位
'Private Const WM_SYSKEYUP = &H105 '弹起系统键位
Private Const VK_CONTROL = 17
Private Const vbKeyZ = 90
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_CHAR = &H102
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Sub 查找窗口句柄getprocessname()
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
Dim hwnd As Long
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
If InStr(strName, "Microsoft Visual Basic - 演示文稿1") Then
hwnd = FindWindow(vbNullString, CStr(strName)) '此处s即所需句柄,您可以在此处中断并获取该句柄,或将句柄数据写入数组以获取所有包含""的窗口句柄
'MsgBox hwnd
hwnd1 = FindWindowEx(hwnd, 0, 0, vbNullString)
'keybd_event vbKeyControl, &H11, 0, 0
PostMessage hwnd, WM_KEYDOWN, VK_CONTROL, vbKeyZ
'keybd_event vbKeyControl, &H11, 0, 0
PostMessage hwnd, WM_KEYUP, VK_CONTROL, vbKeyZ
End If
End If
Loop
End Sub
复制代码 |
|