Jump to content
Sign in to follow this  

Small problem with "GUICtrlCreateList"

Recommended Posts


I have exhausted my searching so I will ask. While this worked (at first) just fine, as I added to my program script, this method no longer seems to function with the mouse. I have to "wake it" with keyboard arrows and even then it takes some prodding to get the selection to move. I have tried a lot of variations of my loop, and oddly enough this function stopped working correctly when I added a small array elsewhere. Could this be a memory issue? Is the some kind of limit to the amount of arrays? And if so, why would it effect this in such a way?

$db = GUICtrlCreateButton ("OK",$dth - 150, $dtv + 155,300,30)
    $dc = GUICtrlCreateList("", $dth - 150, $dtv - 150, 300, 300)
    $d1 = ""
    $d2 = ""
    ;There are 3 items so far read into this list 
    $setup = FileOpen ("deck.ini",0)
    $line = FileReadLine($setup)
    While Not @error = -1
        if StringInStr($line, ":") <> 0 Then
            $n = StringInStr($line, ":")
            $d1 &= StringTrimLeft($line,$n) & "|" 
        $line = FileReadLine($setup)
    $d1 = StringTrimRight ($d1,1)
    $m = StringSplit ($d1,"|")
    $d2 = $m[Random(1,$m[0],1)]
    GuiCtrlSetData($dc, $d1 ,$m[1])
    $d1 = $m[1]
    ;This is the loop where the mouse can't seem to focus on the list.
    $mesg = 0
    While $mesg <> $GUI_EVENT_CLOSE
        $mesg = GUIGetMsg()
            Case $mesg = $dc
                $d1 = GUICtrlRead($dc)
            Case $mesg = $db
    Sleep (250)
    GUICtrlDelete ($db)
    GUICtrlDelete ($dc)

I have read elsewhere on the forum of $WM_NOTIFY being used in such methods, this was working just fine prior to the installation of a small Global array ($cv[8]) Now I can select with keyboard and clicking the button works but I can't select in the list with the mouse. The array is used to display 8 labels, I am working around this by initializing the array after this code above. Apparently it isn't the array but the labels are the issue. So I can continue my work but I would like to know why it happens.


Edited for additional comments.

Edited by XKahn

Share this post

Link to post
Share on other sites


Using this code based on the script you posted I can select items in the list using the mouse and arrow keys without problem:

#include <GUIConstantsEx.au3>

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

$db = GUICtrlCreateButton("OK", 10, 10, 80, 30) ; Had to use my own positions
$dc = GUICtrlCreateList("", 10, 50, 300, 300)
$d1 = ""
$d2 = ""
;There are 3 items so far read into this list
$setup = FileOpen("deck.ini", 0)
$line = FileReadLine($setup)
While Not @error = -1
    If StringInStr($line, ":") <> 0 Then
        $n = StringInStr($line, ":")
                ; Put the "|" at the beginning - then you do not need a trim
                ; Although it will replace any existing list items
        $d1 &= "|" & StringTrimLeft($line, $n)
    $line = FileReadLine($setup)

$m = StringSplit($d1, "|")
$d2 = $m[Random(1, $m[0], 1)]

GUICtrlSetData($dc, $d1, $m[1])

$d1 = $m[1]


;This is the loop where the mouse can't seem to focus on the list.
While 1
    Switch GUIGetMsg()
        Case $dc
            $d1 = GUICtrlRead($dc)
            ConsoleWrite($d1 & @CRLF)
        Case $GUI_EVENT_CLOSE, $db ; With Switch you can have multiple controls per Case

I made a couple of suggested changes - you can see where they are. :)

Desk.ini looked like this:




Could you post the additional code involving the array and labels which when added causes the problem?


P.S. If you could post code which runs without requiring additional lines and an example of the content of any required files it makes a debugger's life much easier! ;)

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


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

Sorry, I forgot to add the ini data for you.

:Marker 1 

Ignored comment about this item
:Title 2

:Item 3

As you can see this first read is to pull the titles trim the ":" from them and present a list of titles and no data. Now with some juggling I managed to get this working but I remain clueless as to how or why my 8 labels caused or effected this function. I have the script working but moved the creation of the 8 blank labels to after rather than before this function. Once the user selects an item, the script reads the file again and stores the data for that block in another function.

I will be placing the completed script in the examples thread soon.

Here is the finished script.

Edited by XKahn

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