如何模拟点击浏览器下载对话框中的“保存”按钮?
'main.frmOption Explicit
Private Sub Command1_Click()
Dim dhk As Long
Dim baocun As Long
Dim id As Long
dhk = 查找窗口("文件下载")
baocun = 查找窗口("保存(&S)", , dhk)
id = GetDlgCtrlID(baocun)
SendMessage baocun, BM_CLICK, 0, ByVal 0&
SendMessage baocun, BM_CLICK, 0, ByVal 0&
End Sub
Private Sub Command2_Click()
Dim dhk As Long
Dim baocun As Long
Dim id As Long
dhk = 查找窗口("文件下载")
baocun = 查找窗口("保存(&S)", , dhk)
id = GetDlgCtrlID(baocun)
SendMessage dhk, WM_COMMAND, id, ByVal baocun
End Sub
--------------------编程问答-------------------- 'window.bas
Option Explicit
Const GW_HWNDNEXT = 2
Const GW_CHILD = 5
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpSting As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public 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
''Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public 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
Public Declare Function GetDlgCtrlID Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetMenu Lib "user32.dll" (ByVal hwnd As Long) As Long
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetMenuItemID Lib "user32.dll" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare Function GetSubMenu Lib "user32.dll" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Function 查找窗口(title As String, Optional model As Boolean = False, Optional parent As Long) As Long
'在parent窗口的子窗口中,查找标题为title的窗口
Dim myhwnd As Long
If parent = 0 Then parent = GetDesktopWindow()
myhwnd = GetWindow(parent, GW_CHILD)
Do While myhwnd
If Left(窗口标题(myhwnd), Len(title)) = title Then
If model Then
If 模式窗口(myhwnd) Then
查找窗口 = myhwnd
Exit Function
End If
Else
查找窗口 = myhwnd
Exit Function
End If
End If
myhwnd = GetWindow(myhwnd, GW_HWNDNEXT)
DoEvents
Loop
End Function
Public Function 窗口标题(myhwnd As Long) As String
Dim hwndLength As Long
Dim FirstText As String
Dim SecondText As String
hwndLength = GetWindowTextLength(myhwnd)
FirstText = String$(hwndLength, 0)
SecondText = GetWindowText(myhwnd, FirstText, (hwndLength + 1))
Debug.Print FirstText
窗口标题 = FirstText
End Function
Public Function 模式窗口(myhwnd As Long) As Boolean
Dim lngStyle As Long
Dim IsModal As Long
IsModal = WS_POPUPWINDOW Or WS_VISIBLE Or WS_DLGFRAME
lngStyle = GetWindowLong(myhwnd, GWL_STYLE)
模式窗口 = ((lngStyle And IsModal) = IsModal)
If 模式窗口 Then Exit Function
IsModal = WS_POPUPWINDOW Or WS_VISIBLE Or WS_EX_DLGMODALFRAME
lngStyle = GetWindowLong(myhwnd, GWL_STYLE)
模式窗口 = ((lngStyle And IsModal) = IsModal)
End Function
Public Function 父窗口标题(myhwnd As Long) As String
Dim hwndparent As Long
hwndparent = GetParent(myhwnd)
Dim hwndparentarentLength As Long
Dim FirstParentText As String
Dim SecondParentText As String
hwndparentarentLength = GetWindowTextLength(hwndparent)
FirstParentText = String$(hwndparentarentLength, 0)
SecondParentText = GetWindowText(hwndparent, FirstParentText, (hwndparentarentLength + 1))
父窗口标题 = FirstParentText
Debug.Print FirstParentText
End Function
--------------------编程问答-------------------- 模拟点击其他按钮没问题,模拟点击ie下载对画框的保存按钮,无效!
请高手帮忙看看! --------------------编程问答-------------------- 推荐使用AutoHotKey软件 --------------------编程问答-------------------- 发现窗体,则 SendKeys() 或 keybd_event 。
--------------------编程问答-------------------- 关注..... --------------------编程问答-------------------- --------------------编程问答--------------------
楼上的不要再这样顶帖,有恶心罐水的嫌疑,不然会处罚
补充:VB , API