本帖最后由 lanfengc 于 2012-5-1 13:12 编辑
给你个例子。这个例子以前在lynfr8写的那个不弹出窗口浏览网页的帖子中发过。 我修改了下,发给你吧。 不知道为什么,监测不到IE的ondragstart事件
具体资料你可以搜索
张硕(CathyEagle)的专栏 《Internet Explorer 编程简述》系列
#include "GUIConstantsEx.au3"
#include <IE.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <array.au3>
Global Const $HandCursorID=0X0001001F
Global $Text,$Text2="",$URL = "http://www.baidu.com/" , $MyMsgboxTitleToStopNavigate="我测试下这个窗口标题弄的特殊点"
$dll = DllOpen("user32.dll")
$GUIMain =GUICreate ( "Event Test", 800,600 ,100,100)
$GUIEdit =GUICtrlCreateEdit ( "Test Log:" & @CRLF, 10, 20, 780, 270)
$StateLab = GUICtrlCreateLabel("Label1", 8, 288, 780, 17)
GUISetState ()
$oIE = ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($oIE,8, 320, 780, 320)
$EventObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
if @error then exit Msgbox(0,"错误!","不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & hex(@error,8))
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall($dll, "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 100, "ptr", DllCallbackGetPtr($Timer))
$oIE.Navigate( $URL )
sleep(1000)
GUISwitch ( $GUIMain )
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
$EventObject.Stop ; 不再接收事件
$EventObject=0 ; 关闭Event Object
$oIE=0 ; 清除内存
GUIDelete ()
DllCall($dll, "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL) ;关闭定时器
DllCallbackFree($Timer) ;释放定时器句柄
DllClose($dll) ;关闭DLL
Exit
EndIf
If _IsPressed("1", $dll) And WinActive($GUIMain) Then ;如果为鼠标按下
WinSetOnTop($GUIMain,"",1)
MsgBox(0,$MyMsgboxTitleToStopNavigate, "0",1,WinGetHandle("Program Manager")) ;弹出一个对话框,断下WBBrowser的Navigate事件
WinSetOnTop($GUIMain,"",0)
If $Text2<>"" Then ;如果获取的网址不为空
$temp=StringRegExp($Text2,"http:\/\/\S{1,100}",3) ;提取HTTP类超链接
ToolTip("你点击的链接是:"&$temp[0])
$oIE.Navigate( StringReplace($temp[0],"/...","") )
EndIf
EndIf
Wend
Func IEEvent_StatusTextChange($Text) ;这是获取状态栏改变
If $Text<>'' And $Text<>'完成' And $Text<>'完毕' Then ;如果找到的是空,完成, 完毕,则不写入到日志
GUICtrlSetData ( $GUIEdit, "IE Status text changed to: " & $Text & @CRLF , "append" )
GUICtrlSetData($StateLab,$Text)
$Text2=$Text
EndIf
EndFunc
Func IEEvent_BeforeNavigate($sUrl) ;这是劫持。 将百度劫持到搜狗。
If StringInStr($sUrl,"baidu") Then
$oIE.Navigate("www.sogou.com")
Else
$Text2=$Text
EndIf
EndFunc
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
If WinExists($MyMsgboxTitleToStopNavigate) Then
WinMove($MyMsgboxTitleToStopNavigate,"",@DesktopWidth,@DesktopHeight,0,0,1)
Send("{Enter}")
EndIf
EndFunc
|