发现任何VB函数、插件、甚至按键精灵对“文件下载”窗口后台失效

引用:http://tieba.baidu.com/f?kz=965486763

提取 保存(s下划线)

 

IE下载资源的时候弹出的“文件下载 - 安全警告”,无法“后台”发送快捷键实现“保存”按钮点击功能。

首先IE安全\自定义设置\文件下载提示-设置为“启用”
然后IE打开下面链接:
http://ishare.iask.sina.com.cn/f/12647953.html
点击“立即下载”按钮, 就会弹出这个“文件下载 - 安全警告”窗口

这个窗口里头的“保存”无论怎么操作,只要是后台,总是无效。

例子:
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName 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 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, ByVal lParam As Long) As Long

Private Const VK_TAB = 
Private Const VK_SHIFT = 
Private Const VK_CONTROL = 
Private Const VK_MENU = &H12 'Alt KEY
Private Const VK_ESCAPE = 

Private Const WM_SETHOTKEY = 

Private Const BM_CLICK = 
Private Const WM_SETTEXT = 
Private Const WM_KEYDOWN = 
Private Const WM_KEYUP = 
Private Const WM_CHAR = 
Private Sub Command1_Click()
    Dim i, hwnd, wHotKey, ans
    'hwnd = FindWindow(vbNull, "文件下载 - 安全警告")
    hwnd = FindWindow(vbNullString, "文件下载 - 安全警告") '无标题 - 记事本
    Debug.Print hwnd
    hwnd = FindWindowEx(hwnd, 0, "Button", "保存(&S)")
    For i = 0 To 100
        '2个函数测试点击
        SendMessage hwnd, BM_CLICK, 0&, 0
        '2个函数测试发送后台按键S
        SendMessage hwnd, WM_CHAR, 83, 0
        PostMessage hwnd, WM_CHAR, 83, 0
        '测试发送组合键ALT+S
        SendMessage hwnd, WM_KEYDOWN, VK_MENU, 0
        SendMessage hwnd, WM_CHAR, 83, 0
        SendMessage hwnd, WM_KEYUP, VK_MENU, 0
    Next
    Debug.Print hwnd
End Sub


执行完了, 窗口依然再哪里。。。。句柄都没问题和SPY++里头得到的按钮句柄一样!!, 为什么不行呢? 来高人解答一下吧, 非常感谢呀!!!

我用按键精灵模拟后台也是对这个窗口无效。。。。这个应该也是系统的一个窗口吧, 应该不特殊才对呀!!!
-------------------------------------
下面是按键精灵的代码
-------------------------------------
Hwnd = Plugin.Window.Find(0, "文件下载 - 安全警告")
TracePrint hwnd & " " & asc("S")
'Hwnd=986866 '按钮的HWND
Call Plugin.Window.Active(Hwnd)

'----以下失效代码 IE下载文件时弹出的“文件下载-安全警告”窗口, 后台无法模拟发送 ALT+S组合键
Call Plugin.Bkgnd.KeyDown(Hwnd, 18)
Call Plugin.Bkgnd.KeyPress(Hwnd, 83)
Call Plugin.Bkgnd.KeyUp(Hwnd, 18)
Call Plugin.Bkgnd.KeyPress(Hwnd, 83)

'鼠标点击按钮也无效
Call Plugin.Bkgnd.LeftClick(Hwnd, 252, 120)

'----以上失效代码

'后台竟然又可以发送 回车键
Plugin.WindowEx3.SetWindowState hwnd,1
Delay 1000
Plugin.WindowEx3.SetWindowState hwnd,5
'Call Plugin.Bkgnd.KeyPress(Hwnd, 13)

Plugin.WindowEx3.SendKey Hwnd,0,83,0

posted @ 2011-12-16 10:46  镇水古月  阅读(541)  评论(0编辑  收藏  举报