Jump to content

guictrlcreatelist(array)


Recommended Posts

I've been working on this all morning, I've got it so it displays the names of who's online when you log in. I need to do it in a better way though, right now if there are more then 2 people logged in, only two will show, and if I create more spaces without people to fill them it will error. I just can't get anything to work the way I need it. I think I need _arraydisplay, but I just cant get that to work right for me. I also need it to update the list of names when some one logs on/off. I've thrown everything at it for that one, and have gottin no where. Any help would greatly be appreciated.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiListBox.au3>
#include <ListboxConstants.au3>
#include <WindowsConstants.au3>

    
    $name = @UserName


IniWrite("s:\test\Config.ini", "Users", $name, "online")
Opt('MustDeclareVars', 1)

Example()

Func Example()
    
    Local $add, $clear, $mylist, $msg, $text, $timestamp, $others, $others2 = "", $userlist, $users, $users2
    
    
    GUICreate("MP Chat", 700, 500) 

    $add = GUICtrlCreateButton("Send", 25, 390, 75, 25, $BS_DEFPUSHBUTTON)
    $clear = GUICtrlCreateButton("Clear", 125, 390, 75, 25)
    $mylist = GUICtrlCreateList("MP Chat initialized", 15, 30, 450, 300)
    $text = GUICtrlCreateInput("", 25, 350, 200, 20) 
    GUICtrlSetLimit ($text, "25")

    GUICtrlSetState ($text, $GUI_FOCUS)
    $userlist = GUICtrlCreateList("", 485, 30, 200, 150,BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL)); List to show array

    
    GUISetState()
    $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                $others2 = $timestamp & guictrlread($text)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
                IniWrite("s:\test\Config.ini", "Chat", "chat", $others2)
                GUICtrlSetData($text, "")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
                
            
        EndSelect
    $users = IniReadSection("s:\test\Config.ini", "Users");problem area beginning
    
    For $i = 1 To $users[0][0]
        
        _GUICtrlListBox_ResetContent($userlist)
        if $users2 <> $userlist Then
            $users = IniReadSection("s:\test\Config.ini", "Users")
            $users2 = $users[1][0] & "  " & $users[1][1] &"|"& $users[2][0] & "  " & $users[2][1]
            GUICtrlSetData ($userlist ,$users2)
            $userlist = $users2
            
        Else
            $users = IniReadSection("s:\test\Config.ini", "Users")
            $users2 = $users[1][0] & "  " & $users[1][1] &"|"& $users[2][0] & "  " & $users[2][1]
            
            
        EndIf
        
    Next                                                                    ;problem area end

                $others = IniRead("s:\test\Config.ini", "Chat", "chat", "")
                if $others <> $others2 and $others2 <> "" Then
                    GUICtrlSetData($mylist, $others)
                    $others2 = $Others
                ElseIf $others2 = "" Then
                    
                Else
                    
                EndIf
            WEnd
            IniWrite("s:\test\Config.ini", "Users", $name, "offline")
EndFunc
Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

config.ini just has what is created in the script and is created when the script starts. when you log in it lists your user name and online under users, and the message that is sent appears under chat. Then when you close the script it lists you as off line.

Giggity

Link to comment
Share on other sites

Thank you Zedna, for 1 and 2, I had it that way several times, but with them that way I got the closest to what I was looking for. As for three. I'm not sure what you mean. The reset content should be in the beginning of the if statement correct? so that if the list does change, it deletes the entities on the list then repopulates with the new ones, but I'm not sure what you mean about where to put the FOR. I have changed it some so that it only lists online people. I don't see why it just flashes right now, and doesn't list the online people. I changed the top for when you sign on too

IniWrite("s:\test\Config.ini", "Users", "online", $name)
and then the FOR expresion too

$users = IniReadSection("s:\test\Config.ini", "Users")
    
    For $i = 1 To $users[0][0]
        
        
        if $users2 <> $users[$i][1] Then; if the ini is changed, it sees that user2's array is no longer equal to users array and does the following
             _GUICtrlListBox_ResetContent($userlist); resets the list
            $users = IniReadSection("s:\test\Config.ini", "Users"); rereads the ini so that if another change occurs it reloads again
            $users2 = $users[$i][1]; sets user2 to the most current array of online users
            GUICtrlSetData ($userlist ,$users2); sets the list to whats arrayed in user2
           
            
        Else
            $users = IniReadSection("s:\test\Config.ini", "Users"); If the ini is not changed it re-reads the ini incase a change is made
        EndIf
        
    Next

I commented in my understanding (or lack there of ) of the statements.

Giggity

Link to comment
Share on other sites

I am so close now, only problem is it flickers, so I'm guessing its looping in the if statement instead of the else. and it shows the number of elements in the array at the top of the list view. How can I fix these? Many thanks for your help so far.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiListView.au3>
#Include <GuiListBox.au3>
#include <ListboxConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Include <File.au3>




If @UserName = "ALLEN PENROD" Then
    $name = "Mike Williams"
Else
    $name = @UserName
EndIf
IniWrite("s:\test\Config.ini", "Users", "online", $name)
Opt('MustDeclareVars', 1)

Example()

Func Example()
    
    Local $add, $clear, $mylist, $msg, $text, $timestamp, $others, $others2 = "", $userlist, $users, $users2
    
    
    GUICreate("MP Chat", 700, 500)

    $add = GUICtrlCreateButton("Send", 25, 390, 75, 25, $BS_DEFPUSHBUTTON)
    $clear = GUICtrlCreateButton("Clear", 125, 390, 75, 25)
    $mylist = GUICtrlCreateList("MP Chat initialized", 15, 30, 450, 300)
    $text = GUICtrlCreateInput("", 25, 350, 200, 20)
    GUICtrlSetLimit ($text, "25")

    GUICtrlSetState ($text, $GUI_FOCUS)
    $userlist = GUICtrlCreateListview("", 485, 30, 200, 150); List to show array
    _GUICtrlListView_AddColumn($userlist, "status", 98)
    _GUICtrlListView_AddColumn($userlist, "users", 98)
    _GUICtrlListView_SetItemCount($userlist, 5000)
    
    GUISetState()
    $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()

        Select
            Case $msg = $add
                $others2 = $timestamp & guictrlread($text)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                GUICtrlSetData($mylist, $timestamp & guictrlread($text),1)
                $timestamp = @HOUR & ":" & @MIN & ":" & @SEC & " " & $name & ": "
                IniWrite("s:\test\Config.ini", "Chat", "chat", $others2)
                GUICtrlSetData($text, "")
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
                
            
        EndSelect
    $users = IniReadSection("s:\test\Config.ini", "Users")
    
    For $i = 1 To $users[0][0]
         
        if $users2 <> $users[$i][1] Then
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($userlist))
            $users = IniReadSection("s:\test\Config.ini", "Users")
            $users2 = $users[$i][1]
            _GUICtrlListview_AddArray($userlist, $users)
           
            
        Else
            $users = IniReadSection("s:\test\Config.ini", "Users")
            $users2 = $users[$i][1]
        EndIf
        
    Next 

                $others = IniRead("s:\test\Config.ini", "Chat", "chat", "")
                if $others <> $others2 and $others2 <> "" Then
                    GUICtrlSetData($mylist, $others)
                    $others2 = $Others
                ElseIf $others2 = "" Then
                    
                Else
                    
                EndIf
            WEnd
            IniWrite("s:\test\Config.ini", "Users", "offline", $name)
EndFunc

Giggity

Link to comment
Share on other sites

against flickering:

1) use

_GUICtrlListView_BeginUpdate ($hListView) 

; all your visible listview data manipulation here ...

_GUICtrlListView_EndUpdate ($hListView)

2) use internal array containing all the data and in your main GUI LOOP update ListView only if your internal array content changes

Edited by Zedna
Link to comment
Share on other sites

1) like this?

$users = IniReadSection("s:\test\Config.ini", "users")

 For $i = 1 To $users[0][0]
         
        if $users2 <> $users[$i][1] Then
            _GUICtrlListView_BeginUpdate ($userlist)
            _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($userlist))
            $users = IniReadSection("s:\test\Config.ini", "users")
            $users2 = $users[$i][1]
            _GUICtrlListview_AddArray($userlist, $users)
            _GUICtrlListView_EndUpdate ($userlist)
           
            
        Else
            $users = IniReadSection("s:\test\Config.ini", "users")
            $users2 = $users[$i][1]
        EndIf
        
    Next

2) I thought thats what the $users2 = $users[$i][1] would do...

The example in the helpfile doesnt have the number of items in the array at the top of the column, what am I doing differently?

Giggity

Link to comment
Share on other sites

1)

$users = IniReadSection("s:\test\Config.ini", "users")


For $i = 1 To $users[0][0]
        
       if $users2 <> $users[$i][1] Then
           _GUICtrlListView_BeginUpdate (GUICtrlGetHandle$userlist))
           _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($userlist))
           $users = IniReadSection("s:\test\Config.ini", "users")
           $users2 = $users[$i][1]
           _GUICtrlListview_AddArray($userlist, $users)
           _GUICtrlListView_EndUpdate (GUICtrlGetHandle$userlist))
          
           
       Else
           $users = IniReadSection("s:\test\Config.ini", "users")
           $users2 = $users[$i][1]
       EndIf
       
    Next

The same applies also for your List control (not only ListView) --> lock it then add all data and finally unlock it

Link to comment
Share on other sites

Ok, I changed to what you have and the flicker stopped, but then when I had someone else sign on, they weren't added. Then I went in the ini and changed mine and it updated the list, but started flickering again. I'm feeling like I'm stabbing in the dark and getting nothing but air... The more I try the more I feel like the way I'm thinking this should work is completely wrong... Maybe I need to set this one aside till I have a better understanding

Giggity

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