Jump to content

IE3.au3 com events - moved from v3 Scripts and Scraps


billmez
 Share

Recommended Posts

At the suggestion of DaleHohm, I've moved this post here to obtain further help with events being passed from com objects, since he felt it was "meaty" enough to deserve its own thread.

What I am attempting to do here is trap and either reuse, redirect, or kill events passed from the browser document object. Specifically in this instance, the context menu, and the new window event. What it will yeild is a tab interface for the browser object, and will lead to development of a RSS parsing module for news feeds.

Any and all help/suggestions/comments are welcome.

billmez

Dale, Beta version is 3.1.1.104

Code below.

OK, thanks -- I'll be interested to see the code. Please also include the beta version that you are running please.

One of the problems with the event code in AutoIt is that the COM implementation doesn't allow passing parameters byRef. This means that the Cancel parameter cannot be handled asynchronously as it is designed to be used and may end up being a limitation for you.

Dale

I have found an event of the MSHTML object that bubbles up, oncontextmenu. In theory $objWin.oncontextmenu.returnValue = False or $oIE.oncontextmenu.returnValue = False should prevent the context menu from displaying. I haven't been able to get it to work yet, even though a return value from the call is true.

As to the parameters by ref, that may be a problem with the new window event since it appears to expect a window object to send the document to. I'll have to try it.

The example I am posting is pointed at one of my web sites. If you look at it, you will see RSS feeds in a table on the left which open another page on the site with the headlines, which open a new window. I want to be able to trap the right click context menu and replace it with one of my own, and open the external feed links in a new tab to produce a stand-alone news/weather application.

My next step after getting this to work will be to code an RSS parser to pull the feeds into a standalone app.

#include <GUIConstants.au3>
#include <ie.au3>

Opt("GUIResizeMode", $GUI_DOCKAUTO)
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
$oIE = ObjCreate("Shell.Explorer.2")
$oMyError = ObjEvent("AutoIt.Error", "_IEAction")
; Create a simple GUI for our output
GUICreate ( "Embedded Web control Test", 800, 600,(@DesktopWidth-800)/2, (@DesktopHeight-600)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUISetOnEvent($GUI_EVENT_CLOSE, "QuitButton")
$GUIActiveX      = GUICtrlCreateObj   ( $oIE,     5, 5 , 790 , 550 )
$GUI_Button_Back    = GuiCtrlCreateButton   ("Back",     10, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Back, "BackButton")
$GUI_Button_Forward = GuiCtrlCreateButton   ("Forward", 90, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Forward, "ForwardButton")
$GUI_Button_Home    = GuiCtrlCreateButton   ("Home",    170, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Home, "HomeButton")
$GUI_Button_Stop    = GuiCtrlCreateButton   ("Stop",    250, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Stop, "StopButton")
$GUI_Button_Refresh = GuiCtrlCreateButton   ("Refresh", 330, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Refresh, "RefreshButton")
$GUI_Button_Ms  = GuiCtrlCreateButton   ("MSDN",    410, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Ms, "MsButton")
$GUI_Button_Au  = GuiCtrlCreateButton   ("AutoIt",  490, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Au, "AuButton")
$GUI_Button_Quit    = GuiCtrlCreateButton   ("Quit",    570, 560, 80,  30)
GUICtrlSetOnEvent($GUI_Button_Quit, "QuitButton")
GUISetState ()   ;Show GUI
;GUISetOnEvent ($GUI_EVENT_SECONDARYDOWN, "doNothing" ,$oIE )


;$oIE.oncontextmenu.returnValue = False

; $Cmenu = $oIE.oncontextmenu.returnValue
; MsgBox(0, "1", $Cmenu)
; $Cmenu2 = $oIE.oncontextmenu.returnValue = False
; MsgBox(0, "2", $Cmenu2)

$oIE.navigate("http://www.wpde.com")

$objWin = _IEDocumentGetObj($oIE)
;$objWin.oncontextmenu.returnValue = False

;_IELoadWait($objWin)



; Waiting for user to close the window
While 1
  Sleep(1000); Idle around
WEnd

    
    
Func QuitButton()
            Exit
EndFunc

Func HomeButton()
      
            $oIE.navigate("http://www.wpde.com")
        EndFunc
        Func MsButton()
      
            $oIE.navigate("http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp")
        EndFunc
        Func AuButton()
      
            $oIE.navigate("http://www.autoitscript.com")
            EndFunc
            Func BackButton()
        
          $retn =   _IEAction($oIE, "back")
            If @error Then
                
            EndIf
            EndFunc
            Func ForwardButton()
       
            _IEAction($oIE, "forward")
            EndFunc
            Func StopButton()
       
            _IEAction($oIE, "stop")
            EndFunc
            Func RefreshButton()
        
            _IEAction($oIE, "refresh")
    EndFunc
Func doNothing()
;$GUI_EVENT_SECONDARYUP
;MsgBox(0, "", "Click")
;$oIE.oncontextmenu.returnValue = False
    Return 0
    EndFunc

; new window event function from MSDN   
;   Private Sub object_NewWindow2( _
;   ByRef ppDisp As Object, _
;   ByRef Cancel As Boolean)

Thanks for the input and the help

billmez

Link to comment
Share on other sites

Bill,

Recent revelations about the way that ObjEvent() works have given insight into why you are having trouble.

I have created a new UDF called _IEInsertEventScript() that I believe will do what you need. There is an example in that post that prevents the right-click context menu.

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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...