Jump to content

Stop mouse right click on a combo box bringing up windows 'cut, copy, paste ....' popup


Recommended Posts

Posted (edited)

This code is mostly from some Swedish sounding guy on the forum (sorry - I can't find the post or his name - think it's Lars)

The code to stop Windows bringing up a popup works for an input box on the GUI but not for a combo box - what am I doing wrong ?

Global $TuneTypes = GUICtrlCreateCombo("", 600+19, 380, 247, 19) ; Combo box to select Recorder type
Global $hInput2 = GUICtrlGetHandle( $TuneTypes )

; Register callback function to subclass Input control for $hInput2
Local $pInputProc = DllCallbackGetPtr( DllCallbackRegister( "InputProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hInput2, $pInputProc, 9999, 0 ) ; SubclassId = 9999, $pData = 0
  
    
; InputProc callback function
Func InputProc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
Switch $iMsg
      Case $WM_CONTEXTMENU, $WM_PASTE, $EM_SHOWBALLOONTIP
      Return 0
EndSwitch
; Call next function in subclass chain
Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] ; _WinAPI_DefSubclassProc
EndFunc

 

Edited by Toyley2
Posted (edited)

It may not be possible with the subclassing method to intercept the right-click on a combo-box as I have not found the right notification to block it.  But with this hook, it is working just fine :

#include <WinAPIProc.au3>
#include <GUIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <WinAPIConstants.au3>
#include <Array.au3>

Global $hGui = GUICreate("Example")

Global $TuneTypes = GUICtrlCreateCombo("", 20, 20, 247, 19)
Global $aPos = ControlGetPos ($hGui, "", $TuneTypes)

Global $hStub = DllCallbackRegister(MyProc, "LRESULT", "int;wparam;lparam")
Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE, DllCallbackGetPtr($hStub), 0, _WinAPI_GetCurrentThreadId())

GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

GUIDelete($hGui)
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub)

Func MyProc($iMsg, $wParam, $lParam)
  If $iMsg = 0 Then
    If $wParam = $WM_RBUTTONDOWN Then
      Local $tPoint = DllStructCreate($tagPOINT, $lParam)
      _WinAPI_ScreenToClient($hGui, $tPoint)
      If $tPoint.X >= $aPos[0] And $tPoint.X < $aPos[0] + $aPos[2] And $tPoint.Y >= $aPos[1] And $tPoint.Y < $aPos[1] + $aPos[3] Then
        Return 1
      EndIf
    EndIf
  EndIf
  Return _WinAPI_CallNextHookEx($hHook, $iMsg, $wParam, $lParam)
EndFunc   ;==>MyProc

ps. next time please provide a runable script so we can test it and modify it without rewriting the whole script for you.  Thanks in advance.

Edited by Nine
Posted

Thank you for the advice and help

sorry Nine - I thought it was just a syntax problem (jumping to conclusions) - I'll put something runnable next time I need help :-)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...