webbrowser模拟确定窗口对话框

webbrowser模拟确定窗口对话框
2009年10月11日
  webbrowser模拟确定窗口对话框
  http://tieba.baidu.com/f?z=123003996&ct=335544320&lm=0&sc=0&rn=30&tn=baiduPostBrowser&word=vb&pn=30
   某些网页出于各种考虑会弹出对话框要求信息确认,往往会中断我们的webbrowser过程,可以使用如下方法:
  1.加入Microsoft Html Object
  2.加入语句
  Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
  Dim obj As HTMLDocument
  Set obj = pDisp.Document
  obj.parentWindow.execScript "function showModalDialog(){return;}" '对showModalDialog引起的对话框进行确定
  End Sub
  而confirm引发的对话确定框可用confirm替换showModalDialog即可,Alert等同理~另一种方法在CSDN看到的方法,过个记录(未尝试)
  Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long ShellExecute frmDisplay.hwnd, vbNullString, "http://www.sina.com", vbNullString, vbNullString, SW_SHOWNORMAL
  
  ____________________________________________________________________
  我使用间隔n秒后发送sendkey"{enter}"能实现,但是这样太垃圾了
  有什么直接控制的方法吗?
  这个问题我已经研究清楚了,使用findwindow,findwindowex,sendmessage,再加time实现了
  下面是代码,大家共享
  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 Const BM_CLICK = &HF5
  Private Sub Timer2_Timer()
  pk = FindWindow(vbNullString, 对话框名) '查找窗体,就是警告对话筐
  pp = FindWindowEx(pk, ByVal 0&, "Button", 按钮名) ' 查找指定窗题上的指定button
  SendMessage pp, BM_CLICK, 0, 0 '给button发送按下消息
  End Sub
  Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
  Cancel = True
  End Sub
  哪有那么麻烦:
  Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
  Dim oDoc1 As HTMLDocument
  Set oDoc1 = pDisp.Document
  oDoc1.parentWindow.execScript "function alert(){return;}"
  oDoc1.parentWindow.execScript "function confirm(){return;}"
  oDoc1.parentWindow.execScript "function showModalDialog(){return;}"
  End Sub
  晕.那么多答案没一个有用的.我遇到过.LZ把这两个事件加进去就行了
  Private Sub WebBrowser1_DownloadBegin()
  WebBrowser1.Silent = True
  End Sub
  Private Sub WebBrowser1_DownloadComplete()
  WebBrowser1.Silent = True
  End Sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值