Jump to content

Block or change Combo context menu??


Recommended Posts

Hi All,

Firstly sorry if this is obvious, I'm teaching myself AutoIT from a self-taught understanding of VBS.

I've been searching the forums and google to no avail. I'd like to create a context menu on a combo box (this combo box).

$Input1 = GUICtrlCreateCombo("", 8, 74, 262, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE))

I have used ;

$ContextCombo = GUICtrlCreateContextMenu($Input1)
$RightClickCopy = GUICtrlCreateMenuItem("Copy", $ContextCombo)
GUICtrlSetOnEvent($RightClickCopy, "RightClickCopy")
$RightClickPaste = GUICtrlCreateMenuItem("Paste", $ContextCombo)
GUICtrlSetOnEvent($RightClickPaste, "RightClickPaste")

Which works and give me the menu but only on the drop down arrow rather than on the whole box.

From the text part of the control I get what looks like a system context menu. Can I replace this with my two options or hide the system menu so only the arrow works?

Edited by Smiley1244
Link to comment
Share on other sites

  • Moderators

Smiley1244,

Welcome to the AutoIt forum. :oops:

As the "text" part of a combo is actually an input control, I do not believe you can create a context for it. The Help file page for GUICtrlCreateContextMenu says:

"Note: You can't create context menus for controls that already have system context menus, i.e. edit or input controls"

Sorry about that - better luck with your next question! :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi and thanks,

Is there no way of stopping it appearing then?

I found a way for edit boxes but I am failing utterly to make it work for the input control.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)
Global $iDLLUser32 = DllOpen("user32.dll");open a handle to user32.dll library
;this keeps an open handle to the library instead of opening and closing it with each call to CallWindowProcW()
Global $hGUI = GUICreate("Disable Edit Context Menu", 300, 200), $msg
Global $cEdit1 = GUICtrlCreateEdit("", 10, 10, 280, 150)
Global $hEdit1 = GUICtrlGetHandle($cEdit1)
;register a callback function for the edit control window procedure
Global $wProcHandle = DllCallbackRegister("_EditWndProc", "ptr", "hwnd;uint;wparam;lparam")
;subclass the edit control by substituting its window procedure for our own "_EditWndProc"
Global $wProcOld = _WinAPI_SetWindowLong($hEdit1, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;restore the original window procedure callback.
;failure to call this func results in a script crash on exit
_WinAPI_SetWindowLong($hEdit1, $GWL_WNDPROC, $wProcOld)
;free the callback function
DllCallbackFree($wProcHandle)
DllClose($iDLLUser32)
GUIDelete($hGUI)
Exit
;subclassed edit control window procedure
Func _EditWndProc($hWnd, $msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $hWnd
        Case $hEdit1
            Switch $msg
                Case $WM_CONTEXTMENU ; block the context menu from running
                    Return 1
            EndSwitch
    EndSwitch
    ;pass on all other edit control messages to the controls original window procedure
    Local $aRet = DllCall($iDLLUser32, "int", "CallWindowProcW", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $msg, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return 0
    Return $aRet[0]
EndFunc   ;==>_EditWndProc
Link to comment
Share on other sites

  • Moderators

Smiley1244,

Try using _GUICtrlComboBox_GetComboBoxInfo to get the handle of the input like this: :bye:

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <Constants.au3>

$hGUI = GUICreate("", 500, 500)

$hComboBox = GUICtrlCreateCombo("Combo", 10, 40, 100, 21)

$tInfo = $tagCOMBOBOXINFO
If _GUICtrlComboBox_GetComboBoxInfo($hComboBox, $tInfo) Then
    ConsoleWrite("Handle to the combo ........: " & DllStructGetData($tInfo, "hCombo") & @CRLF)
    ConsoleWrite("Handle to the input ........: " & DllStructGetData($tInfo, "hEdit") & @CRLF)
    ConsoleWrite("Handle to the drop-down list: " & DllStructGetData($tInfo, "hList") & @CRLF)
EndIf

GUISetState()

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

Once you have the handle, you can subclass it as you did with the edit control above. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Smiley1244,

Glad I could help. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

For anyone that stumbles across this; Here is the code that put together blocks the context menu of a combo box and displays a custom menu instead.

I cannot take credit for any of this code but I've looked at so many pages today on this I cannot track back to who did what, I am however resposible for the mashing togther and for that I'm sorry :oops:

I hope it helps someone

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
Global $iDLLUser32 = DllOpen("user32.dll");open a handle to user32.dll library
Global $hGUI = GUICreate("Disable Edit Context Menu", 300, 200), $msg
Global $cEdit1 = GUICtrlCreateCombo("", 8, 74, 262, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_UPPERCASE))
Global $tInfo, $hEdit1
Global $DummyMenu     = GUICtrlCreateDummy()
Global $ContextMenu    = GUICtrlCreateContextMenu($DummyMenu)
Global $CommonMenuItem = GUICtrlCreateMenuItem("Common", $ContextMenu)
Global $FileMenuItem   = GUICtrlCreateMenuItem("File", $ContextMenu)
GUICtrlCreateMenuItem("", $ContextMenu)
Global $ExitMenuItem   = GUICtrlCreateMenuItem("Exit", $ContextMenu)
If _GUICtrlComboBox_GetComboBoxInfo($cEdit1, $tInfo) Then
$hEdit1 = DllStructGetData($tInfo, "hEdit")
EndIf
Global $wProcHandle = DllCallbackRegister("_EditWndProc", "ptr", "hwnd;uint;wparam;lparam")
;subclass the edit control by substituting its window procedure for our own "_EditWndProc"
Global $wProcOld = _WinAPI_SetWindowLong($hEdit1, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;restore the original window procedure callback.
;failure to call this func results in a script crash on exit
_WinAPI_SetWindowLong($hEdit1, $GWL_WNDPROC, $wProcOld)
;free the callback function
DllCallbackFree($wProcHandle)
DllClose($iDLLUser32)
GUIDelete($hGUI)
Exit
Func _EditWndProc($hWnd, $msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    Switch $hWnd
        Case $hEdit1
            Switch $msg
    Case $WM_CONTEXTMENU ; About to show Context menu
     ShowMenu($hGUI, $ContextMenu) ;Show our context
                    Return 1 ;Block system context
            EndSwitch
    EndSwitch
    ;pass on all other edit control messages to the controls original window procedure
    Local $aRet = DllCall($iDLLUser32, "int", "CallWindowProcW", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $msg, "wparam", $wParam, "lparam", $lParam)
    If @error Then Return 0
    Return $aRet[0]
EndFunc   ;==>_EditWndProc

Func ShowMenu($hWnd, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    $arPos = MouseGetPos()
    Local $x = $arPos[0]
    Local $y = $arPos[1]
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc
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...