NerdFencer Posted March 13, 2009 Share Posted March 13, 2009 I am writing a program sort of like Task Manager but different. I have started with the Users tab, but have encountered a problem. After the update routine runs, the items loose their order. What is the best way to maintain the sort order? This is the file that the problem is in expandcollapse popup#include-once #Include <GuiListView.au3> #include "InfoStore.au3" Global $UserTab Global $UserTabItems[3] Global $UsersContent[3][6] Func UsersPopulate() Local $temp ReDim $UsersContent[$LoggedOnUsers[0][0]][6] For $i = 1 To $LoggedOnUsers[0][0] $temp = UsersStats($LoggedOnUsers[$i][1]) $UsersContent[$i-1][0] = $LoggedOnUsers[$i][1] $UsersContent[$i-1][1] = $temp[0] $UsersContent[$i-1][2] = $temp[1] $UsersContent[$i-1][3] = $temp[2] $UsersContent[$i-1][4] = $LoggedOnUsers[$i][2] $UsersContent[$i-1][5] = $LoggedOnUsers[$i][0] Next EndFunc Func UsersCreate() GUICtrlCreateTabItem("Users") $UserTab = GUICtrlCreateListView("User|Processes|CPU|RAM|ID|Domain",2,21,395,348) _GUICtrlListView_SetColumnWidth($UserTab, 0, 120) _GUICtrlListView_SetColumnWidth($UserTab, 5, 150) UsersUpdate() _GUICtrlListView_RegisterSortCallBack($UserTab) GUIRegisterMsg(0x004E, "UsersSortCallback") EndFunc Func UsersUpdate() Local $new = "", $temp ReDim $UserTabItems[$LoggedOnUsers[0][0]] _GUICtrlListView_DeleteAllItems($UserTab) For $i = 1 To $LoggedOnUsers[0][0] Step 1 $temp = UsersStats($LoggedOnUsers[$i][1]) $new = $LoggedOnUsers[$i][1]&"|"&$temp[0]&"|"&$temp[1]&"|"&$temp[2]&"|"&$LoggedOnUsers[$i][2]&"|"&$LoggedOnUsers[$i][0] $UserTabItems[$i-1]=GUICtrlCreateListViewItem($new,$UserTab) Next EndFunc Func UsersSoftUpdate() If $LoggedOnUsers[0][0]==UBound($UserTabItems) Then UsersPopulate() For $i=1 To UBound($UserTabItems) For $j=0 To 5 If Not(_GUICtrlListView_GetItemText($UserTab, $i-1, $j) == $UsersContent[$i-1][$j]) Then _GUICtrlListView_SetItemText($UserTab, $i-1, $UsersContent[$i-1][$j],$j) EndIf Next Next Else UsersUpdate() EndIf EndFunc Func UsersStats($user) Local $Number[3] = [0,0,0], $temp[3] For $i = 1 To $Process[0][0] Step 1 $temp = StringSplit($Process[$i][3],"\") If $temp[0]>=2 Then If $temp[2]==$user Then $Number[0] = $Number[0] + 1 $Number[1] = $Number[1] + $Process[$i][6] $Number[2] = $Number[2] + $Process[$i][7] EndIf EndIf Next $Number[1] = String($Number[1])&"%" $Number[2] = String($Number[2])&" B" Return $Number EndFunc Func UsersSortCallback($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $UserTab If Not IsHWnd($UserTab) Then $hWndListView = GUICtrlGetHandle($UserTab) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ; Kick off the sort callback _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) ; No return value EndSwitch EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc The whole program is attached Help Plz Task_Program.zip _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
Achilles Posted March 13, 2009 Share Posted March 13, 2009 Just call this function: _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))After your updates are done... Instead of the DllStruct... part just put the column index you're sorting your list by. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
NerdFencer Posted March 13, 2009 Author Share Posted March 13, 2009 I cant seem to get this to work, can you post an example? _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
Achilles Posted March 13, 2009 Share Posted March 13, 2009 #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> GUICreate("ListView Add SubItem", 400, 300) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, $LVS_EX_FULLROWSELECT) GUISetState() ; Add columns _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100) _GUICtrlListView_RegisterSortCallBack($hListView) ; Add items _GUICtrlListView_AddItem($hListView, "a", 0, _GUICtrlListView_GetItemCount($hListView) + 9999) _GUICtrlListView_AddSubItem($hListView, 0, "1", 1, 1) _GUICtrlListView_AddItem($hListView, "b", 1, _GUICtrlListView_GetItemCount($hListView) + 9999) _GUICtrlListView_AddSubItem($hListView, 1, "3", 1, 1) _GUICtrlListView_AddItem($hListView, "c", 1, _GUICtrlListView_GetItemCount($hListView) + 9999) _GUICtrlListView_AddSubItem($hListView, 2, "2", 1, 1) ToolTip("NOT SORTED") Sleep(2000) _GUICtrlListView_SortItems($hListview, 1); sorts the entire listview based off the column with index 1 (the second one) ToolTip("SORTED") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now