Sign in to follow this  
Followers 0
Brickoneer

Disable Right-Clicking

3 posts in this topic

I'm pretty sure this has been asked before, but I couldn't find it. So, sorry for the repeat!

I have an embedded IE browser in my GUI, and I don't want the users to be able to have the right-click options that they would in a regular browser. Can I disable right-clicking on a certain control? or even the GUI itself?

Thanks!

Brick

P.S. I tried simply disabling the control... that works except EVERYTHING is disabled. (duh!)

P.P.S. Also... how would you have an IE browser autoscroll to the bottom of a page? My only clue is controlsend some 'Page Down's

Thanks Again!

Share this post


Link to post
Share on other sites



Check this out:

#include <GUIConstants.au3>
#include <IE.au3>
#Include <Misc.au3>

_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
GUICreate("Embedded Web control Test", 640, 400, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 600, 360)

GUISetState()       ;Show GUI

_IENavigate ($oIE, "http://www.google.com")
_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('LOL. Sorry. You cannot rightclick');return false")
; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
;~      Case $msg=$GUI_EVENT_SECONDARYDOWN
;~          MsgBox(0,"","Secondary button disabled")
    EndSelect
WEnd

GUIDelete()

Exit

I LOVE _IEHeadInsertEventScript (). This will show you a message when you right click. If you don't want it to do anything, replace:

_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "alert('LOL. Sorry. You cannot rightclick');return false")

With:

_IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "return false")

This will disable right-clicking on that page only.

When the user navigates to a different webpage, right-clicking will be re-enabled. Add this case in the main loop to partially fix that:

Case $msg = $GUI_EVENT_PRIMARYDOWN
            _IELoadWait($oIE)
            _IEHeadInsertEventScript ($oIE, "document", "oncontextmenu", "return false")

It won't work if the user uses the keyboard to navigate.

Share this post


Link to post
Share on other sites

Many thanks!

Brick

Share this post


Link to post
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
Sign in to follow this  
Followers 0