`
mqttb32q
  • 浏览: 14095 次
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics