Jump to content

ObjEvent usage.


milos83
 Share

Go to solution Solved by trancexx,

Recommended Posts

Meh, I forgot that you can make event functions execute synchronously. LOL and I wrote the code for that.

Yes, you can get id or object that fired the event from within event function:

Global $oIE = ObjCreate("InternetExplorer.Application")
Local $oEventBrowser = ObjEvent($oIE, "Browser_", "DWebBrowserEvents2")
Local $oEventLink1, $oEventButton2 ; to collect event objects to

$oIE.navigate("about:blank")


;-----------------------------------------------
While Sleep(100)
WEnd
; THE END
;-----------------------------------------------

Func Customize($oBrowser, ByRef $oEventLink1, ByRef $oEventButton2)
    Local $sHtml = '<body> <a id="idLink" href="#" title="Link" >Click me</a> <br><br> <button id="idButton" title="Button" >Click me</button> </body>'
    Local $oDoc = $oBrowser.document
    $oDoc.write($sHtml)

    $oBrowser.visible = True

    Local $oLink1 = $oDoc.getElementById("idLink")
    Local $oButton2 = $oDoc.getElementById("idButton")

    ; Event objects
    $oEventLink1 = ObjEvent($oLink1, "Event_", "HTMLAnchorEvents2")
    $oEventButton2 = ObjEvent($oButton2, "Event_", "HTMLButtonElementEvents2")
EndFunc


;Events for browser
Func Browser_OnQuit()
    Exit
EndFunc

Func Browser_DocumentComplete($oDisp, $sUrl)
    Customize($oDisp, $oEventLink1, $oEventButton2)
EndFunc



; Events
volatile Func Event_onmouseover($oEvtObj)
    If IsObj($oEvtObj) Then
        ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onmouseover" & @CRLF)
        Switch $oEvtObj.srcElement
            Case $oIE.document.getElementById("idLink")
                $oEvtObj.srcElement.innerhtml = "Hovering Anchor"
            Case $oIE.document.getElementById("idButton")
                $oEvtObj.srcElement.innerhtml = "Hovering Button (click to Exit)"
        EndSwitch
    EndIf
EndFunc

volatile Func Event_onmouseout($oEvtObj)
    If IsObj($oEvtObj) Then
        ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onmouseout" & @CRLF)
        Switch $oEvtObj.srcElement ; check
            Case $oIE.document.getElementById("idLink")
                $oEvtObj.srcElement.innerhtml = "Not Hovering Anchor"
            Case $oIE.document.getElementById("idButton")
                $oEvtObj.srcElement.innerhtml = "Not Hovering Button (click to Exit)"
        EndSwitch
    EndIf
EndFunc

volatile Func Event_onclick($oEvtObj)
    If IsObj($oEvtObj) Then
        ConsoleWrite("id = " & $oEvtObj.srcElement.id & " fired onclick" & @CRLF)
        If $oEvtObj.srcElement = $oIE.document.getElementById("idButton") Then
            $oIE.Quit()
            Exit
        EndIf
    EndIf
EndFunc

Then It has to be HTMLAnchorEvents2, HTMLButtonElementEvents2, etc...

You can compare id-s or objects directly to get the one that fired (i'm checking objects in that example).

 

That does it!

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...