Jump to content

Disable right click on control


Recommended Posts

Hello. With an autoit GUI there are several way for intercept a mouse click ( _IsPressed, $WM_LBUTTONDOWN, $GUI_EVENT_PRIMARYDOWN) but i don't have found nothing to disable a right-left click inside the GUI-Control except using low level hook. I'm miss something or there isn't any "classic" way? Thanks

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Subclassing (read and process Windows messages before they reach the destination control or window) is a common way. Here (the example for GUICtrlCreateEdit in the Help file) right click is canceled in the Edit control and no context menu shows up:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>

Example()

Func Example()
  GUICreate("My GUI edit") ; will create a dialog box that when displayed is centered

  Local $idMyedit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32, 121, 97, $ES_AUTOVSCROLL + $WS_VSCROLL)
  Local $hMyedit = GUICtrlGetHandle( $idMyedit )

  ; Subclassing Edit control
  Local $pEditCallback = DllCallbackGetPtr( DllCallbackRegister( "EditCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
  _WinAPI_SetWindowSubclass( $hMyedit, $pEditCallback, 1, 0 ) ; $iSubclassId = 1, $pData = 0

  GUISetState(@SW_SHOW)

  Send("{END}")

  ; will be append dont' forget 3rd parameter
  GUICtrlSetData($idMyedit, "Second line", 1)

  ; Loop until the user exits.
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop

    EndSwitch
  WEnd
  GUIDelete()
EndFunc   ;==>Example

Func EditCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  ; If $iMsg <> $WM_RBUTTONUP then call next function in subclass chain (this forwards messages to Edit control)
  If $iMsg <> $WM_RBUTTONUP Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
  Return 0 ; If $iMsg = $WM_RBUTTONUP then cancel the message by returning 0
EndFunc

 

Link to comment
Share on other sites

The problem of subclassing is if i have example 10 controls i need to do 10 _WinAPI_SetWindowSubclass, right? Is strange that we can intercept the message using GUIRegisterMsg or GUIGetMsg but we can't stop the message in any native way.

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Yes, but if it's the same controls (eg. Edit controls) you can use the same callback function.

You can use GUIRegisterMsg to cancel many Windows messages. But not the mouse messages because they are used by the internal AutoIt code.

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