Jump to content

How to disable right click


Recommended Posts

Global Const $GUI_EVENT_CLOSE = -3

_Main()
Func _Main()
    Local $OCSE2, $GUIActiveX, $gui_button_Exit, $Msg

    $OCSE2 = ObjCreate("Shell.Explorer.2")

    GUICreate("Google", 800, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
    GUISetBkColor(0x000000)

    $GUIActiveX = GUICtrlCreateObj($OCSE2, 10, 45, 780, 350)

    $gui_button_Exit = GUICtrlCreateButton("Exit", 710, 5, 80, 30)
    GUICtrlSetBkColor(-1, 0xFFFFFF)

    $OCSE2.navigate("http:\\www.google.com")
    GUISetState()

    While 1
        $Msg = GUIGetMsg()
        Select
            Case $Msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $Msg = $gui_button_Exit = $GUI_EVENT_CLOSE
                ExitLoop

        EndSelect
    WEnd
    GUIDelete()
EndFunc

i am new no idea to disable right click in GUICtrlCreateObj

I am new, i am not programmer.....

Sorry my bad English......

Link to comment
Share on other sites

Have a look at this topic, it seems you will need to insert some javascript to stop the context menu from coming up with _IEHeadInsertEventScript:

.

Edited by MikahS
function name

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Glad to help. ^_^

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Also, for a single web page, you can use _IEHeadInsertEventScript (see example #2) :

#Include <IE.au3>
#Include <GUIConstantsEx.au3>

$oIE = _IECreateEmbedded()

GUICreate("Google", 800, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
GUISetBkColor(0x000000)

$GUIActiveX = GUICtrlCreateObj($oIE, 10, 45, 780, 350)

$gui_button_Exit = GUICtrlCreateButton("Exit", 710, 5, 80, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)

_IENavigate($oIE, "http://www.google.com")
GUISetState()

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

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE , $gui_button_Exit
            ExitLoop
    EndSwitch
WEnd

 

Link to comment
Share on other sites

jguinch

Thanks to reply, im create already this script

My Work

#Include <IE.au3>
#Include <GUIConstantsEx.au3>

$oIE = _IECreateEmbedded()

$gui = GUICreate("Google", 800, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
GUISetBkColor(0x000000)

$GUIActiveX = GUICtrlCreateObj($oIE, 10, 45, 780, 350)

$gui_button_Exit = GUICtrlCreateButton("Exit", 710, 5, 80, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)

GUISetState()

GUISetState(@SW_DISABLE, $gui)
_IENavigate($oIE, "http://www.google.com")
_IEHeadInsertEventScript($oIE, "document", "oncontextmenu", "return false;")
GUISetState(@SW_ENABLE, $gui)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE , $gui_button_Exit
            ExitLoop
    EndSwitch
WEnd

 

I am new, i am not programmer.....

Sorry my bad English......

Link to comment
Share on other sites

I noticed after navigating to a new page the eventscript no longer applies and Right-Click functionality resumes.  One way I found this can be addressed is to register objevent and listen for NavigateComplete events.

#include <IE.au3>
#include <GUIConstantsEx.au3>

$oIE = _IECreateEmbedded()

GUICreate("Google", 800, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2)
GUISetBkColor(0x000000)

$GUIActiveX = GUICtrlCreateObj($oIE, 10, 45, 780, 350)

$gui_button_Exit = GUICtrlCreateButton("Exit", 710, 5, 80, 30)
GUICtrlSetBkColor(-1, 0xFFFFFF)

Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")
_IENavigate($oIE, "http://www.google.com")


GUISetState()


While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE, $gui_button_Exit
            ExitLoop
    EndSwitch
WEnd

;https://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htm
Func _IEEvent_NavigateComplete2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel)
    _DisableRightClick()
EndFunc   ;==>_IEEvent_NavigateComplete2

Func _DisableRightClick()
    _IEHeadInsertEventScript($oIE, "document", "oncontextmenu", "return false;")
EndFunc   ;==>_DisableRightClick

edit: code tags

Edited by spudw2k
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...