ugnius40 Posted May 10, 2012 Posted May 10, 2012 Hi, I'm creating ListBox with _GuiCtrlListBox_Create and I want my programm to react as soon as item is selected in list box, here is my code: #include <GUIConstantsEx.au3> #include <GUIListBox.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $hGUI, $msg, $mylist, $file2, $selection $hGUI = GUICreate("My GUI list") $file2 = GUICtrlCreateInput("", 10, 200, 300, 20) ; GUI List Box: $mylist = _GuiCtrlListBox_Create($hGUI, "", 176, 32, 121, 97, BitOR($LBS_STANDARD, $LBS_NOTIFY)) ; Add Items to List Box _GUICtrlListBox_BeginUpdate($mylist); _GUICtrlListBox_AddString($mylist, "Line 0") _GUICtrlListBox_AddString($mylist, "Line 1") _GUICtrlListBox_AddString($mylist, "Line 2") _GUICtrlListBox_AddString($mylist, "Line 3") _GUICtrlListBox_AddString($mylist, "Line 4") _GUICtrlListBox_EndUpdate($mylist); ; Activate GUI` GUISetState() ; Main Message Loop While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $mylist ; <===!!!===> this code never runs $selection = _GUICtrlListBox_GetSelItems($mylist) GUICtrlSetData($file2, $selection[1]) EndSwitch WEnd EndFunc ;==>Example But the code that should react to list box changes is never called, how do I go about it. Sorry if this is silly question, I'm just starting with AutoIt, I've tried googling this but cannot find definite answer how to handle this. Thanks. This is my first post. Ugnius
Moderators Melba23 Posted May 10, 2012 Moderators Posted May 10, 2012 ugnius40,Welcome to the AutoIt forum. Controls created with the native GUICtrl(Control)Create functions return a ControlID - this is the index of the control in an internal array maintained within AutoIt to identify the control. It is a simple integer.But if you use a UDF _GUICtrl(ControlType)_Create function then you get a handle returned - this is the unique ID used by Windows to identify everything on the system. It is of a special hex format.So when you use $mylist in your GUIGetMsg loop there is no way that the function will return that value - and so you get no response. If you use the UDF functions, you need much more complicated code to detect events - as shown in the example for _GUICtrlListBox_Create in the Help file. So my recommendation would be to use the native functions (GUICtrlCreateList in this case) as then you can use the GUIGetMsg loop as you originally wished: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cList = GUICtrlCreateList("", 10, 10, 200, 200) For $i = 1 To 25 GUICtrlSetData($cList, "Item " & $i) Next GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cList $sItem = GUICtrlRead($cList) MsgBox(0, "Selected", $sItem) EndSwitch WEndAll clear? Please ask if not. 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
ugnius40 Posted May 10, 2012 Author Posted May 10, 2012 Thanks Melba23, I guess I'll stick to native controls, I thought <GuiListBox.au3> functions only work with UDF created controls but they seem to work with native also. First bump passed, more to come. Thanks again, Ugnius
Moderators Melba23 Posted May 10, 2012 Moderators Posted May 10, 2012 ugnius40, Be wary of mixing the native and UDF functions - it is always best to stick to one or the other if you can. Good luck - and you know where we are if the next bump is a big one. 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
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