The code I have works fine, but it flickers alot while it does mass resorting everytime people join or leave the channel, so I'm wondering if there's anyway to improve the code, or is there an alterative way to sort the channel list? The channel list I have is a listview by the way. You'll also see the duplication avoidance code I put in place- if you know of a better way, I'm open to suggestions. The one I have works, but if there's an alternative, that'd be more than welcome.
Sorting code:
Public Sub SortList(ctlListView As ListView, intColulunHeaderIndex As Integer, Optional Ascending As Boolean, Optional Descending As Boolean)
ctlListView.Refresh
DoEvents
ctlListView.Sorted = True
ctlListView.SortKey = intColulunHeaderIndex
If Ascending = True Then
ctlListView.SortOrder = lvwAscending
ElseIf Descending = True Then
ctlListView.SortOrder = lvwDescending
Else
If ctlListView.SortOrder = lvwAscending Then
ctlListView.SortOrder = lvwDescending
Else
ctlListView.SortOrder = lvwAscending
End If
End If
DoEvents
ctlListView.Refresh
End Sub
Section in user join handlers code:
Case &H2
'User entered
On Error GoTo skipuserenteredadd
Set list_item = DMBot.lstChanView.ListItems.Add(, Username, "")
If Flags And &H20 Then
SortOrder = 6 'Squelched
icons = 10
ElseIf Flags And &H40 Then
SortOrder = 4 'blizz guest
ElseIf Flags And &H4 Then
SortOrder = 3 'speaker
ElseIf Flags And &H2 Then
SortOrder = 2 'op
icons = 3
ElseIf Flags And &H8 Then
SortOrder = 1 'bnet rep
ElseIf Flags And &H1 Then
SortOrder = 0 'blizz rep
Else
SortOrder = 5
UserProduct = Mid(TextString, 1, 4)
If UserProduct = "PXES" Then
icons = 1
ElseIf UserProduct = "RATS" Then
icons = 4
ElseIf UserProduct = "PX3W" Then
icons = 8
ElseIf UserProduct = "3RAW" Then
icons = 6
Else
Icon = 1
End If
End If
list_item.SmallIcon = icons
list_item.SubItems(1) = Username
list_item.SubItems(2) = Ping
list_item.SubItems(3) = SortOrder
MainModule.SortList DMBot.lstChanView, 3, True, False
ChannelCount = ChannelCount + 1
AddC vbGreen, Username & " has entered the channel."
Username = ""
skipuserenteredadd:
If Err.Number <> 35602 And Err.Number <> 0 Then
AddC vbRed, "RTE: " & Err.Number & ", Err Dscrp: " & Err.Description
Else
Err.Clear
End If
Thanks for any and all ideas/advice, and also for reading this, in advance!
redraw it and it wont flicker
Quote from: Tazo on September 25, 2005, 09:20 AM
redraw it and it wont flicker
The redrawing is what's making it flicker.
Oh-my bad, I didn't even read the code lol I just thought that redrawing it removed the flicker
I wrote a channel list sorting thing that worked fine...and then I lost it.
But what I did was avoid any sorting code at all. When someone joins the channel, it puts them (and everyone else) in the right place. I wrote a sub to do this and called it when Bnet sent me the users in channel and when a user joined. I used some different code for when a user aquired ops.
I think you can disable the listview before making changes to it to avoid the flicker as well. (.Enabled = False)
Thanks Stealth! While it didn't eliminate the flickering, that certainly reduced it by alot.
You should use LockWindowUpdate to disable the flickering.
Call LockWindowUpdate(ctlListView.hWnd)
' stuff..
Call LockWindowUpdate(0)