VB6.0,用右擊任務欄,屬性,打開的窗口進行測試,可以按取消按鈕,成功
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 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 SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const BM_CLICK As Long = &HF5
Private Sub Command1_Click()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, "任務欄和「開始」菜單屬性") '我找的是任務欄屬性窗口,這里換成你要找的窗口標題
'MsgBox hwnd
Dim btnhWnd As Long
btnhWnd = FindWindowEx(hwnd, 0, "Button", "取消") '取消是按按鈕的標題,你要換成自己的內容
MsgBox btnhWnd
SetActiveWindow hwnd
SendMessage btnhWnd, BM_CLICK, 0, 0
End Sub
該文章在 2014/4/9 16:20:17 編輯過