Jump to content

I have a problem with WinList


Recommended Posts

Ok, i am trying to list some clients from silkroad online. But I have the problem that the lisview doesnt refresh ones the script is opened

include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

$Client=WinList("[CLASS:CLIENT]")

$Form1 = GUICreate("Silkroad Client Manager", 595, 170, 193, 125)
$listview = GUICtrlCreateListView("Client Name", 8, 8, 250, 150,$LVS_SORTDESCENDING&$LVS_LIST&$LVS_SHOWSELALWAYS)
$Button1 = GUICtrlCreateButton("Min", 272, 8, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Max", 352, 8, 75, 25, 0)
$Button3 = GUICtrlCreateButton("Hide", 432, 8, 75, 25, 0)
$Button4 = GUICtrlCreateButton("Show", 512, 8, 75, 25, 0)
$Button5 = GUICtrlCreateButton("Exit", 392, 136, 75, 25, 0)
$Button6 = GuiCtrlCreateButton("Refresh",272, 75, 72,25,0)
#Region Clients
If $Client[0][0] = 0 Then
$item=GUICtrlCreateListViewItem("No Clients Found",$listview)
Else
If $Client[0][0] > 1 or $Client[0][0] = 1  Then
$item1=GUICtrlCreateListViewItem($Client[1][0],$listview)
If $Client[0][0] > 2 or $Client[0][0] = 2  Then
$Item2=GUICtrlCreateListViewItem($Client[2][0],$listview)
If $Client[0][0] > 3 or $Client[0][0] = 3  Then
$Item3=GUICtrlCreateListViewItem($Client[3][0],$listview)
If $Client[0][0] > 4 or $Client[0][0] = 4  Then
$Item4=GUICtrlCreateListViewItem($Client[4][0],$listview)
If $Client[0][0] > 5 or $Client[0][0] = 5  Then
$Item5=GUICtrlCreateListViewItem($Client[5][0],$listview)
If $Client[0][0] > 6 or $Client[0][0] = 6  Then
$Item6=GUICtrlCreateListViewItem($Client[6][0],$listview)
If $Client[0][0] > 7 or $Client[0][0] = 7  Then
$Item7=GUICtrlCreateListViewItem($Client[7][0],$listview)
If $Client[0][0] > 8 or $Client[0][0] = 8  Then
$Item8=GUICtrlCreateListViewItem($Client[8][0],$listview)
If $Client[0][0] > 9 or $Client[0][0] = 9  Then
$Item9=GUICtrlCreateListViewItem($Client[9][0],$listview)
If $Client[0][0] > 10 or $Client[0][0] = 10  Then
$Item10=GUICtrlCreateListViewItem($Client[10][0],$listview)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf   
EndIf
EndIf   
EndIf
#EndRegion

Func _Refresh()
GuiCtrlDelete($listview)        
$listview = GUICtrlCreateListView("Client Name", 8, 8, 250, 150,$LVS_SORTDESCENDING&$LVS_LIST&$LVS_SHOWSELALWAYS)
If $Client[0][0] = 0 Then
$item=GUICtrlCreateListViewItem("No Clients Found",$listview)
Else
If $Client[0][0] > 1 or $Client[0][0] = 1  Then
$item1=GUICtrlCreateListViewItem($Client[1][0],$listview)
If $Client[0][0] > 2 or $Client[0][0] = 2  Then
$Item2=GUICtrlCreateListViewItem($Client[2][0],$listview)
If $Client[0][0] > 3 or $Client[0][0] = 3  Then
$Item3=GUICtrlCreateListViewItem($Client[3][0],$listview)
If $Client[0][0] > 4 or $Client[0][0] = 4  Then
$Item4=GUICtrlCreateListViewItem($Client[4][0],$listview)
If $Client[0][0] > 5 or $Client[0][0] = 5  Then
$Item5=GUICtrlCreateListViewItem($Client[5][0],$listview)
If $Client[0][0] > 6 or $Client[0][0] = 6  Then
$Item6=GUICtrlCreateListViewItem($Client[6][0],$listview)
If $Client[0][0] > 7 or $Client[0][0] = 7  Then
$Item7=GUICtrlCreateListViewItem($Client[7][0],$listview)
If $Client[0][0] > 8 or $Client[0][0] = 8  Then
$Item8=GUICtrlCreateListViewItem($Client[8][0],$listview)
If $Client[0][0] > 9 or $Client[0][0] = 9  Then
$Item9=GUICtrlCreateListViewItem($Client[9][0],$listview)
If $Client[0][0] > 10 or $Client[0][0] = 10  Then
$Item10=GUICtrlCreateListViewItem($Client[10][0],$listview)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf   
EndFunc
GUISetState(@SW_SHOW)

guictrlread($listview)


While 1
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button5
            Exit
        Case $Button1
            $ClientName = GUICtrlRead(GUICtrlRead($listview))
            $Fix = StringRegExpReplace($ClientName, "[|]", "")
            WinSetState($Fix, "",@SW_MINIMIZE)

                
        Case $Button2
            $ClientName = GUICtrlRead(GUICtrlRead($listview))
            $Fix = StringRegExpReplace($ClientName, "[|]", "")
            WinSetState($Fix, "",@SW_MAXIMIZE)
            
        Case $Button3
            $ClientName = GUICtrlRead(GUICtrlRead($listview))
            $Fix = StringRegExpReplace($ClientName, "[|]", "")
            WinSetState($Fix, "",@SW_HIDE)
            
        Case $Button4
            $ClientName = GUICtrlRead(GUICtrlRead($listview))
            $Fix = StringRegExpReplace($ClientName, "[|]", "")
            WinSetState($Fix, "",@SW_SHOW)
            
        Case $Button6   
            _Refresh()
    EndSwitch
WEnd
Edited by Moonshadow312
Link to comment
Share on other sites

I don't have Silkroad online and I don't really get what you are asking for :P but my advice concerning the script is the following:

1. You are processing the data from WinList() a strange way, check the helpfile.

2. Your code are not written very cleverly, read about arrays and Func in the helpfile.

3. It's really hard to read without proper indentions, if you can't do them yourself then try Tidy, it will make reading much easier and more understandable.

Link to comment
Share on other sites

Ok I will rewrite my question. How do you refresh a listview?

In this Case, the list view diplays the windows with the class client. So if you open the script, all windows with class client will be displayed. But ones the script is open, the listview doesnt refresh anymore. So if I open a new client, the listview doesnt show it.

So the problem is, How am I able to refresh a listview ???

Edited by Moonshadow312
Link to comment
Share on other sites

Ok I think I understand what you mean now.

I almost did a complete rewrite of your script to get it smaller and more readable and I think I fixed your problem with updating the listview but that's untested since I don't have Silkroad.

If it work then for your own sake compare it with your own script and try to understand why I did what, you could perhaps learn something from it! And don't be afraid of asking questions if there is something you don't understand! :P

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>

Global $Client[1][1], $Array[1]

$Form1 = GUICreate("Silkroad Client Manager", 595, 170, 193, 125)
$listview = GUICtrlCreateListView("Client Name", 8, 8, 250, 150, BitOR($LVS_SORTDESCENDING, $LVS_LIST, $LVS_SHOWSELALWAYS));The right way to have multiple styles is with BitOr()
$Button1 = GUICtrlCreateButton("Min", 272, 8, 75, 25);setting the style to 0 doesn't do anything so removed all of them
$Button2 = GUICtrlCreateButton("Max", 352, 8, 75, 25)
$Button3 = GUICtrlCreateButton("Hide", 432, 8, 75, 25)
$Button4 = GUICtrlCreateButton("Show", 512, 8, 75, 25)
$Button5 = GUICtrlCreateButton("Exit", 392, 136, 75, 25)
$Button6 = GUICtrlCreateButton("Refresh", 272, 75, 72, 25)

_Refresh()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button5
            Exit
        Case $Button1
            _SetState(@SW_MINIMIZE)
        Case $Button2
            _SetState(@SW_MAXIMIZE)
        Case $Button3
            _SetState(@SW_HIDE)
        Case $Button4
            _SetState(@SW_SHOW)
        Case $Button6
            _Refresh()
    EndSwitch
WEnd

Func _SetState($State)
    $Array = _GUICtrlListView_GetSelectedIndices($listview, True)
    For $Y = 1 To $Array[0]
        WinSetState($Client[$Array[$Y]][1], "", $State)
    Next
EndFunc

Func _Refresh()
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_DeleteAllItems($listview)
    $Client = WinList("[CLASS:CLIENT]")
    If $Client[0][0] > 0 Then
        For $X = 1 To $Client[0][0]
            GUICtrlCreateListViewItem($Client[$X][0], $listview)
        Next
    Else
        GUICtrlCreateListViewItem("No Clients Found", $listview)
    EndIf
    _GUICtrlListView_EndUpdate($listview)
EndFunc  ;==>_Refresh
Link to comment
Share on other sites

  • 1 year later...

the

_setstate not workin properly

the main window disapear instead of the notepad window

here its more easy to show

i changed the class to notepad

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>

Global $Client[1][1], $Array[1]

$Form1 = GUICreate("Silkroad Client Manager", 595, 170, 193, 125)
$listview = GUICtrlCreateListView("Client Name", 8, 8, 250, 150, BitOR($LVS_SORTDESCENDING, $LVS_LIST, $LVS_SHOWSELALWAYS));The right way to have multiple styles is with BitOr()
$Button1 = GUICtrlCreateButton("Min", 272, 8, 75, 25);setting the style to 0 doesn't do anything so removed all of them
$Button2 = GUICtrlCreateButton("Max", 352, 8, 75, 25)
$Button3 = GUICtrlCreateButton("Hide", 432, 8, 75, 25)
$Button4 = GUICtrlCreateButton("Show", 512, 8, 75, 25)
$Button5 = GUICtrlCreateButton("Exit", 392, 136, 75, 25)
$Button6 = GUICtrlCreateButton("Refresh", 272, 75, 72, 25)

_Refresh()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button5
            Exit
        Case $Button1
            _SetState(@SW_MINIMIZE)
        Case $Button2
            _SetState(@SW_MAXIMIZE)
        Case $Button3
            _SetState(@SW_HIDE)
        Case $Button4
            _SetState(@SW_SHOW)
        Case $Button6
            _Refresh()
    EndSwitch
WEnd

Func _SetState($State)
    $Array = _GUICtrlListView_GetSelectedIndices($listview, True)
    For $Y = 1 To $Array[0]
        WinSetState($Client[$Array[$Y]][1], "", $State)
    Next
EndFunc

Func _Refresh()
    _GUICtrlListView_BeginUpdate($listview)
    _GUICtrlListView_DeleteAllItems($listview)
    $Client = WinList("[CLASS:Notepad]")
    If $Client[0][0] > 0 Then
        For $X = 1 To $Client[0][0]
            GUICtrlCreateListViewItem($Client[$X][0], $listview)
        Next
    Else
        GUICtrlCreateListViewItem("No Clients Found", $listview)
    EndIf
    _GUICtrlListView_EndUpdate($listview)
EndFunc  ;==>_Refresh
Edited by royco
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...