关于ObjEvent的疑问
下面的代码中对ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") 中的IEEvent_不是太明白,为什么又出来一个Func IEEvent_ProgressChange($Progress,$ProgressMax),前后关系不清楚,其中的参数又是如何传递的呢对COM组件还一知半解
; ObjEvent example
ProgressOn("Example", "Loading page...")
$oIE=ObjCreate("InternetExplorer.Application.1") ; Create Internet Explorer application
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") ; Assign events to UDFs starting with IEEvent_
; Do some browsing activities
$oIE.Visible=1
$oIE.RegisterAsDropTarget = 1
$oIE.RegisterAsBrowser = 1
$oIE.Navigate( "http://www.AutoItScript.com/" )
sleep(3000) ; Give it time to load the web page
$SinkObject=0 ; Stop IE Events
$oIE.Quit ; Quit IE
$oIE=0
exit
; one of many Internet Explorer Event Functions
Func IEEvent_ProgressChange($Progress,$ProgressMax)
$percent = Int( ($Progress * 100) / $ProgressMax )
If $percent >= 0 And $percent <= 100 Then
ProgressSet ( $percent , $percent & " percent to go." , "loading web page" )
EndIf
EndFunc
Exit
; COM Error Handler example
; -------------------------
$oIE=ObjCreate("InternetExplorer.Application.1") ; Create Internet Explorer application
Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Initialize a COM error handler
$oIE.UnknownMethod ; Deliberately call an undefined method
If $g_eventerror then
$g_eventerror = 0
Msgbox (0,"AutoItCOM test","Test passed: We got an error number: " & @error)
Else
Msgbox (0,"AutoItCOM test","Test failed!")
Endif
Exit
; This is my custom defined error handler
Func MyErrFunc()
Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF& @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number,8)& @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext _
)
Local $err = $oMyError.number
If $err = 0 Then $err = -1
$g_eventerror = $err; to check for after this function returns
Endfunc 包含一个已经得到的Object(对象)的事件句柄.
ObjEvent ( $ObjectVar, "functionprefix" [, "接口名称"] )
ObjEvent ( "AutoIt.Error" [, "函数名称"] )
参数
$ObjectVar 包含一个要接收对象事件的变量
"functionprefix" 你定义处理接受事件函数的前缀.
前缀附加对象方法名称.
"接口名称" 事件接口的可选名称.
注意:它必须是一个支持即将传出的对象,而且必须发送类型.
谢谢回复,确实有用,虽然是官方帮助文档上的翻译,不过当时没有仔细看,经这么一说才明白过来。
现在还有个问题
Func IEEvent_ProgressChange($Progress,$ProgressMax)
里面两个参数怎么传递过来,谁来赋这两个参数的值呢 WebBrowser(浏览器控件) 的事件接口,就是你在Au3中创建的浏览器对象,当你使用该对象打开网页的时候,该对象便会产生事件ProgressChange,同事传递参数给Au3
页:
[1]