Jump to content
Sign in to follow this  

ListBox LB_GETTEXT bug?

Recommended Posts


Hi folks,

My GUI has a listbox containing filepaths. and a button that does what is equivalent to a DELETE ALL function (which will delete the files and remove the items in the listbox as they are deleted). It's wierd but my FOR...NEXT loop would not delete everything. I found that at some point, $LB_GETTEXT will return some garbage in the text. Would really appreciate it if someone could take a look. THanks in advance...

Here's my code...

#include <GuiConstants.au3>

$LB_GETCOUNT        = 0x18B
$LB_GETTEXT         = 0x0189
$FileList = "c:\file01.txt|c:\file02.txt|c:\file03.txt|c:\file04.txt|c:\file05.txt|c:\file06.txt|c:\file07.txt|c:\file08.txt|c:\file09.txt"

GuiCreate("LB Test", 299, 291,-1, -1)

$List_1 = GuiCtrlCreateList("", 10, 10, 280, 227);,$LBS_MULTISELECT)
$Button_2 = GuiCtrlCreateButton("Delete ALL", 10, 250, 80, 30)

While 1
    $msg = GuiGetMsg()
    Case $msg = $GUI_EVENT_CLOSE
    Case $msg = $Button_2
        $items_count = _GUICtrlListCount($List_1); count the number of items in listbox
        For $i = 0 to $items_count - 1
            $FileToDelete = _GUICtrlListGetText($List_1, $i)
                                                                    MsgBox(262144,'Debug line ~31','Selection:' & @lf & '$FileToDelete ' & @lf & @lf & 'Return:' & @lf & $FileToDelete  & @lf & @lf & '@Error:' & @lf & @Error & @lf & @lf & '@Extended:' & @lf & @Extended);### Debug MSGBOX
        ; FileDelete($FileToDelete)
            _GUICtrlListDeleteItem($List_1, $i)

Func _GUICtrlListCount($h_listbox)
    Return GUICtrlSendMsg($h_listbox, $LB_GETCOUNT, 0, 0)
EndFunc  ;==>_GUICtrlListCount

Func _GUICtrlListDeleteItem($h_listbox, $i_index)
    Return GUICtrlSendMsg($h_listbox, $LB_DELETESTRING, $i_index, 0)
EndFunc  ;==>_GUICtrlListDeleteItem

Func _GUICtrlListGetText($h_listbox, $i_index)
    Return GUICtrlRecvMsg($h_listbox, $LB_GETTEXT, $i_index, 1)
EndFunc  ;==>_GUICtrlListGetText

Share this post

Link to post
Share on other sites

Func _GUICtrlListGetText($h_listbox, $i_index)
    Return GUICtrlRecvMsg($h_listbox, $LB_GETTEXT, $i_index, 1)
EndFunc ;==>_GUICtrlListGetText


It should be:

Func _GUICtrlListGetText($h_listbox, $i_index)
    Return GUICtrlSendMsg($h_listbox, $LB_GETTEXT, $i_index, 1)
EndFunc ;==>_GUICtrlListGetText

GUICtrlRecvMsg --> GUICtrlSendMsg

Share this post

Link to post
Share on other sites

@gafrost, by god, you're right. I'm laughing at myself as I type. :whistle: too embarassing. :"> . I should've guessed the items would be renumbered after each deletion. Glad I don't do this for a living. Thanks again and until my next booboo.

Edited by kalayaan

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.