Jump to content
Sign in to follow this  

cannot write multiple values to listbox

Recommended Posts


For some reason I cant send multiple values to my list box, for example when I press the add button it adds text to the list box, but if I press it again it just overwrites the first one.

Heres my code

#include <GuiConstants.au3>
#include <File.au3>

;Creates the parent gui with buttons, menu's text fields

$gui = GUICreate("Troyzilla 1.0", @DesktopWidth, @DesktopHeight, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_MAXIMIZE)
        GUISetState( @SW_MAXIMIZE )
    $back = GUICtrlCreateButton("Back", 10, 20, 40, 30,  $BS_BITMAP)
    $forward = GUICtrlCreateButton("Forward", 55, 20, 40, 30, $BS_BITMAP)
    $refresh = GUICtrlCreateButton("Refresh", 100, 20, 40, 30, $BS_BITMAP)
    $GO = GUICtrlCreateButton("GO", 810, 20, 50, 30, $BS_BITMAP)
    $Combo_5 = GUICtrlCreateCombo("http://www.google.com", 150, 25, 640, 21, $GUI_DEFBUTTON)
    $pic = GUICtrlCreatePic("images\troyzilla.jpg", 890, 5, 85, 53)
    $filemenu = GUICtrlCreateMenu ("&File")  ;creates the file menu
        $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)  ;creates open in the file menu
        $exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)    ;Creates exit in the file menu
        $saveitem = GUICtrlCreateMenuitem ("Save",$filemenu);Creates Save in the file menu
            GUICtrlSetState(-1, $GUI_DEFBUTTON)
        $recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)   ;Creates recent items in the file menu
        $separator1 = GUICtrlCreateMenuitem ("",$filemenu,2);creates a separator line
    $helpmenu = GUICtrlCreateMenu ("Help")   ;Creates the help menu
        $infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)    ;Creates info in the help menu
    $viewmenu = GUICtrlCreateMenu("View",-1,1);Creates view menu
        $viewfavitem = GUICtrlCreateMenuitem ("Favorites",$viewmenu) ;Creates Favorites in the view menu

;Sets the picture of the buttons on the page
    GUICtrlSetImage ( $back, "images\back.bmp") 
    GUICtrlSetImage ( $Forward, "images\forward.bmp")
    GUICtrlSetImage ( $refresh, "images\refresh.bmp")
    GUICtrlSetImage ( $GO, "images\go.bmp")
;Creates the info gui
$info = GUICreate("About Troyzilla", 290, 382,(@DesktopWidth-290)/2, (@DesktopHeight-382)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE, $WS_EX_TOOLWINDOW)
    $OK = GuiCtrlCreateButton("OK", 80, 330, 120, 40)
    $Pic_2 = GuiCtrlCreatePic("images/info.jpg", 0, 0, 290, 310)
    GUISetState( @SW_HIDE, $info )  
$fav = GuiCreate("Projects" , 235, 670,2, 80 , $WS_CHILD + $WS_VISIBLE + $WS_SIZEBOX + $WS_EX_TOOLWINDOW ,"", $gui)

    $Add = GuiCtrlCreateButton("Add", 20, 50, 70, 30)
    $Delete = GuiCtrlCreateButton("Delete", 130, 50, 70, 30)
    $Favorites_label = GuiCtrlCreateLabel("Favorites", 20, 20, 210, 20)
    $Close = GuiCtrlCreateButton("Close", 70, 630, 70, 30)
    $favlist = GUICtrlCreateList("", 2, 85, 230, 550, $LBS_SORT )
        GuiSetState(@SW_HIDE, $fav)

;creates the child gui that the dll will be held in.
$internetgui = GUICreate("", @DesktopWidth -15, @DesktopHeight - 190, 3, 78, $WS_CHILD + $WS_BORDER, "", $gui)

;opens dll then calls it.
$dll = DllOpen("cwebpage.dll")
    DllCall($dll, "long", "EmbedBrowserObject", "hwnd", $internetgui)
    DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", "http://www.google.com")

While 1
    $msg = GUIGetMsg() 
        Case $msg = $GUI_EVENT_CLOSE; states that if the close button is it the script will exit
            if WinActive($info) Then
        Case $msg = $GO 
            DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", GUICtrlRead($Combo_5)); tells the dll to go to the web page thats in the combobox
        Case  $msg = $back 
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 0);tells the webpage to go back
        Case $msg = $forward
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 1);tells the webpage to go forward
        Case $msg = $refresh 
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 4);tells the webpage to refresh
        Case $msg = $exititem; sets the exit item in the menu to exit
        Case $msg = $OK 
            GUISetState( @SW_HIDE, $info ); tells the info gui to hide
    ; makes the open file box and makes it open the file in the webpage dll
        Case $msg = $fileitem  
            $file = FileOpenDialog("Open","C:","HTML (*.html;*.htm)")
            If @error <> 1 Then GUICtrlCreateMenuitem ($file ,$recentfilesmenu)
            If $msg = $fileitem Then DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", $file)
    ;makes the save file box and saves the current page 
        Case $msg = $saveitem
            $save = FileSaveDialog ("Save", @DesktopDir, "Html (*.html)", 3, "")
                InetGet(GUICtrlRead($Combo_5), $save & ".html", 1,0)

        Case $msg = $infoitem               
            GuiSetState(@SW_SHOW, $info); shows the info gui
        Case $msg = $viewfavitem
            WinMove($internetgui, "", 245, 78,@DesktopWidth - 250, @DesktopHeight - 190)
                GuiSetState(@SW_SHOW, $fav); shows the fav gui          
            Dim $Page

            _FileReadToArray ( "fav\fav.txt", $page )
                For $x = 1 to $page[0]
                    GUICtrlSetData($favlist, GuiCtrlRead ( $favlist ) & "|" & $page)
        Case $msg = $Close
                GuiSetState(@SW_HIDE, $fav); shows the fav gui
                WinMove($internetgui, "", 3, 78,@DesktopWidth -15, @DesktopHeight - 190)
        Case $msg = $Add
                FileWriteLine("fav\fav.txt", GUICtrlRead($Combo_5))
                GUICtrlSetData($favlist, GuiCtrlRead ( $favlist ) & "|" & GUICtrlRead($Combo_5))


[quote]Randy:This is for what?! Arresting me for what?! I'm not allowed to stand up for myself?! I thought this was America! Huh? Isn't this America?! I'm sorry! I thought this was America![/quote]

Share this post

Link to post
Share on other sites

from the help GuiCtrlRead

Combo, List: The value selected

being you have nothing selected nothing is put back in, and if you read about the GuiCtrlSetData if it starts with | it is overwritten.

Edit: If you don't mind working with beta, the beta has UDFs (User Defined Functions) for working with the listbox, just look for _GUICtrlList

Beta is available here.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs


Don't argue with an idiot; people watching may not be able to tell the difference.


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.