Sign in to follow this  
Followers 0
ugnius40

Why _GuiCtrlListBox_Create ListBox events are not captured in loop?

4 posts in this topic

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

Share this post


Link to post
Share on other sites



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. :D

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

WEnd

All clear? Please ask if not. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0