Jump to content

Small problem with "GUICtrlCreateList"


XKahn
 Share

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) & "|" 
        EndIf
        $line = FileReadLine($setup)
    WEnd
    FileClose($setup)
    $d1 = StringTrimRight ($d1,1)
    
    $m = StringSplit ($d1,"|")
    $d2 = $m[Random(1,$m[0],1)]
    
    GuiCtrlSetData($dc, $d1 ,$m[1])
    GuiSetState()
    $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()
        Select
            Case $mesg = $dc
                $d1 = GUICtrlRead($dc)
            Case $mesg = $db
                ExitLoop
        EndSelect
    WEnd 
    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.

Thanks.

Edited for additional comments.

Edited by XKahn
Link to comment
Share on other sites

  • Moderators

XKahn,

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)
    EndIf
    $line = FileReadLine($setup)
WEnd
FileClose($setup)

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

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

$d1 = $m[1]

GUISetState()

;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
            Exit
    EndSwitch
WEnd

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

Desk.ini looked like this:

1:1

1:2

1:3

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

M23

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! ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

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

:Marker 1 
0,0,0,0,0,0,0,0
80,D,-5,SP,0,2,0,my.jpg

Ignored comment about this item
:Title 2
13,4,E,0,0,-8,H,x
24,5,E,0,0,-10,H,MAXE.JPG
22,10,E,0,0,-15,H,BAXE.JPG
14,1,A,0,0,-4,P,W
41,4,A,0,0,-6,P,0
22,6,A,0,0,-8,H,R

:Item 3
t,t,t,t,a,a,a,a
1,2,3,4,5,6,7,8
always,8,items,separated,by,commas,go,here

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...