gruntydatsun Posted May 25, 2011 Share Posted May 25, 2011 Hello, I've searched for this one and can't find the answer. Any help appreciated. I would like to run a function when a selection is made in the combobox (called $combo_Selection) in code below. #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Example Program", 315, 149, 192, 114) $combo_Selection = GUICtrlCreateCombo("", 24, 24, 241, 25) $label_RelatedInfo = GUICtrlCreateLabel("label_RelatedInfo", 24, 64, 87, 17) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") GUICtrlSetData($combo_Selection, "Dog|Cat|Goat|Chicken","Dog") While 1 Sleep(1000) WEnd Func Terminate() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 25, 2011 Moderators Share Posted May 25, 2011 (edited) gruntydatsun, A bit of a kludge, but it works: expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> $fCurrState = False $fOpened = False $Form1 = GUICreate("Example Program", 315, 149, 192, 114) $combo_Selection = GUICtrlCreateCombo("", 24, 24, 241, 25) $label_RelatedInfo = GUICtrlCreateLabel("label_RelatedInfo", 24, 64, 87, 17) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") GUICtrlSetData($combo_Selection, "Dog|Cat|Goat|Chicken", "Dog") While 1 Sleep(10) $fState = _GUICtrlComboBox_GetDroppedState($combo_Selection) If $fState <> $fCurrState Then Switch $fState Case True $fOpened = True Case False If $fOpened Then $fOpened = False MsgBox(0, "Function", "Run it now using " & GUICtrlRead($combo_Selection)) EndIf EndSwitch $fCurrState = $fState EndIf WEnd Func Terminate() Exit EndFunc ;==>Terminate There should be a message from the combo somewhere we can intercept - I will look around tomorrow. M23 Edit: Found it: expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> $fFlag = False $Form1 = GUICreate("Example Program", 315, 149, 192, 114) $combo_Selection = GUICtrlCreateCombo("", 24, 24, 241, 25) $label_RelatedInfo = GUICtrlCreateLabel("label_RelatedInfo", 24, 64, 87, 17) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") GUICtrlSetData($combo_Selection, "Dog|Cat|Goat|Chicken", "Dog") GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Sleep(10) ; Look for the flag If $fFlag Then $fFlag = False MsgBox(0, "Function", "Run it now using " & GUICtrlRead($combo_Selection)) EndIf WEnd Func Terminate() Exit EndFunc ;==>Terminate Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam) ; if it is our combo and it is closed after have been opened If BitAND($wParam, 0x0000FFFF) = $combo_Selection And BitShift($wParam, 16) = $CBN_CLOSEUP Then ; Set a flag $fFlag = True EndIf Return $GUI_RUNDEFMSG EndFunc You need to use a flag becasue you do not want to run long functions from within the message handler. All clear? Edited May 25, 2011 by Melba23 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...
UEZ Posted May 25, 2011 Share Posted May 25, 2011 Here my version: expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Example Program", 315, 149, 192, 114) $combo_Selection = GUICtrlCreateCombo("", 24, 24, 241, 25) GUICtrlSetOnEvent(-1, "Combo") $label_RelatedInfo = GUICtrlCreateLabel("label_RelatedInfo", 24, 64, 87, 17) GUISetState(@SW_SHOW) Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") GUICtrlSetData($combo_Selection, "Dog|Cat|Goat|Chicken","") While 1 Sleep(1000) WEnd Func Combo() Call(GUICtrlRead($combo_Selection)) EndFunc Func Dog() ConsoleWrite("Running dog" & @CRLF) EndFunc Func Cat() ConsoleWrite("Running cat" & @CRLF) EndFunc Func Goat() ConsoleWrite("Running goat" & @CRLF) EndFunc Func Chicken() ConsoleWrite("Running chicken" & @CRLF) EndFunc Func Terminate() Exit EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
gruntydatsun Posted May 26, 2011 Author Share Posted May 26, 2011 Thanks Melba23. That was exactly what I was looking for. Implemented it my program and it works great. Thanks for your version too UEZ. It's news to me that I can call a function by the name of a element of a combobox. You get better support for AutoIT than you do for 99% of paid products. Thanks guys. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2011 Moderators Share Posted May 26, 2011 gruntydatsun, And here is an even more elegant way to code it - in my opinion, of course. expandcollapse popup#include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiComboBox.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Example Program", 315, 149, 192, 114) GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") $combo_Selection = GUICtrlCreateCombo("", 24, 24, 241, 25) GUICtrlSetData($combo_Selection, "Dog|Cat|Goat|Chicken", "Dog") $label_RelatedInfo = GUICtrlCreateLabel("label_RelatedInfo", 24, 64, 87, 17) ; Create a dummy control to run the function $hDummy = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "Do_It") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Sleep(10) WEnd Func Do_It() MsgBox(0, "Function", "Run it now using " & GUICtrlRead($combo_Selection)) EndFunc Func Terminate() Exit EndFunc ;==>Terminate Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam) ; if it is our combo and it is closed after have been opened If BitAND($wParam, 0x0000FFFF) = $combo_Selection And BitShift($wParam, 16) = $CBN_CLOSEUP Then ; Fire the dummy GUICtrlSendToDummy($hDummy) EndIf Return $GUI_RUNDEFMSG EndFunc 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...
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