Smiley1244 Posted April 2, 2012 Share Posted April 2, 2012 (edited) 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 April 2, 2012 by Smiley1244 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 2, 2012 Moderators Share Posted April 2, 2012 Smiley1244,Welcome to the AutoIt forum. 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! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Smiley1244 Posted April 2, 2012 Author Share Posted April 2, 2012 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. expandcollapse popup#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 More sharing options...
Moderators Melba23 Posted April 2, 2012 Moderators Share Posted April 2, 2012 Smiley1244,Try using _GUICtrlComboBox_GetComboBoxInfo to get the handle of the input like this: #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 WEndOnce you have the handle, you can subclass it as you did with the edit control above. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Smiley1244 Posted April 2, 2012 Author Share Posted April 2, 2012 Thanks Melba, Got there in the end that works great. I can now display my custom menu options by using a dummy ctrl. It's very cut and paste from 3 peoples code but it woks and I can now tidy it up Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 2, 2012 Moderators Share Posted April 2, 2012 Smiley1244, Glad I could help. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Smiley1244 Posted April 2, 2012 Author Share Posted April 2, 2012 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 I hope it helps someone expandcollapse popup#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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now