Sign in to follow this  
Followers 0
jacq

SOLVED:Change right mouse menu

3 posts in this topic

#1 ·  Posted (edited)

Welcome

How can I disable pressing the right button on the gui input or make it possible but with functions  paste only.

The paste option would be best.

#include <GUIConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
 
Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
 
$Parent1 = GUICreate("Program", 550, 260, -1, -1) ; width, height, position on screen from left 
 
 
 
$Text= GUICtrlCreateLabel("Nazwa", 30, 20, 400, 20)
 
 
$name = GUICtrlCreateInput("", -400, 5, 300, 20)
 
 
GUISetOnEvent($GUI_EVENT_CLOSE, "Events")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "Events")
 
GUISetState(@SW_SHOW)
 
While 1
Sleep(10)
Wend
 
Func verPressed()
Run("winver")
EndFunc
 
While 1
Sleep(10)
Wend
 
 
 
 
 
Func Events()
 
Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit
 
Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
 
Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
 
Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN
MsgBox(64, "Click", "Right click not allowed")
 
EndSelect
 
EndFunc

I found this code and tried to add it to my code, but still I have errors.

#include <GuiConstants.au3>
#Include <Misc.au3>
$Gui = GUICreate("Right Click Test", 400, 400)
 
;- ///// Credit an Edit and Input box to show contextual menus for //////
$edit = GUICtrlCreateEdit("Test Information", 0, 0, 400, 200)
$input = GUICtrlCreateInput("Test Input", 0, 220, 120, 25)
 
;- //// Create a dummy Context Menu ////////
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
;- //// Add the 'Disabled' item to the menu //////
    GUICtrlCreateMenuItem("Disabled", $ContextMenu)
 
;- //// Open the DLL responsible for keyclicks/controls/etc ////
$dll = DllOpen("user32.dll")
 
GUISetState()
 
While 1
 
    $Msg = GUIGetMsg()
 
;- //// If the right 'menu' context key is pressed then show the disabled context menu ////
    if _IsPressed("5D", $dll) Then
            Context($Gui, $ContextMenu)
    EndIf
    
    Select
        Case $Msg = $gui_event_close
            DllClose($dll)
            Exit
 
;- //// If the Right Mouse Button is clicked, show the disabled context menu ////
        Case $Msg = -9
            Context($Gui, $ContextMenu)
 
    EndSelect
WEnd
 
;- //// This is the context menu function to be able to show the menu ////
Func Context($hWnd, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
 
;- /// Get current mouse position ////
    $arPos = MouseGetPos()
 
;- /// Break up mouse positions into variables ////
    Local $x = $arPos[0]
    Local $y = $arPos[1]
 
;- //// Call the dll file opened above to show the custom context menu at the current mouse position ////
    DllCall($dll, "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>ShowMenu
Edited by jacq

Share this post


Link to post
Share on other sites



Try this:

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Global Enum $idPaste = 1000

$hGUI = GUICreate("Test", 300, 200)
$Input = GUICtrlCreateInput("Input Test", 16, 16, 100, 25)

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "Paste", $idPaste)
GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete($hGUI)
DllCallbackFree($wProcHandle)

Func _WindowProc($hWnd, $msg, $wParam, $lParam)
    Switch $hWnd
        Case GUICtrlGetHandle($Input)
            Switch $msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idPaste
                            MsgBox(0, 0, "Put Func Here")
                    EndSwitch
            EndSwitch
    EndSwitch
    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, "hwnd", $hWnd, "uint", $msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc   ;==>_WindowProc

Share this post


Link to post
Share on other sites

Thanks this code is cool

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