steff Posted February 2, 2011 Share Posted February 2, 2011 Hello everybody in the code attached, I'm tryng to build a GUI containing, alternatively, a user list and a computer list. I want also to be able to click on the column headers to sort the columns. I can do that on both lists, but when the Computer list is ordered, just the first char of any item is displayed. Please, run it and you will see. (there are many includes, since this code is an adaptation from a bigger program) Surely I'm missing something in the sorting commands, but I didn't understand yet. Thanks for all replies stefano expandcollapse popup#include <AD.au3> #include <array.au3> #include <Array2D.au3> #include <_sql.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <WinAPI.au3> #include <GuiListBox.au3> #Include <GuiButton.au3> Opt("GUIOnEventMode", 1) Global $numUser=5 Global $numPC=3 Global $GUI_start_X=10 Global $GUI_start_Y=10 Global $GUI_listgroup_width=400 Global $GUI_listgroup_height=300 Global $GUI_list_width=390 Global $GUI_list_height=290 Global $button_X=$GUI_start_X+10 Global $button_Y=$GUI_start_Y+20 Global $button_width=60 Global $button_height=60 Global $msgboxTop=262144 Global $userList, $computerList Global $users[5][3] = [["jon", "jon gut", 1],["joe", "joe hoe", 1],["jim", "jimbo", 2],["john", "john doe", 0],["marge", "margareth simpsons", 0]] Global $computer[5][3] = [["pc1", "working"],["pc2", "not working"],["pc3", "working" ],["pc4", "not working" ],["pc5", "working" ]] _main() Func _main() Local $iI ; Create GUI Global $guiHd=GUICreate("Monitor", 950,430) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") _UserList_create() _setup_create() ; Loop until user exits While 1 Sleep(1000) ; Idle around WEnd EndFunc ;==>_main Func _setup_create() GUICtrlCreateGroup("Setup", $GUI_start_X, $GUI_start_Y, 80, 340) $btnUsersSetup = GUICtrlCreateButton("User Setup", $button_X, $button_Y+$button_height+20, $button_width, $button_height, $BS_MULTILINE) GUICtrlSetOnEvent(-1, "_UserList_create") $btnAdminSetup = GUICtrlCreateButton("Computer Setup", $button_X, $button_Y+($button_height*2)+40, $button_width, $button_height, $BS_MULTILINE) GUICtrlSetOnEvent(-1, "_ComputerList_create") EndFunc ;========================= ; ; USER RELATED FUNCTIONS ; ;========================= Func _UserList_create() Local $GUI_start_list_X=$GUI_start_X+110 Local $GUI_start_list_Y=$GUI_start_Y+20 Local $GUI_start_listgroup_X=$GUI_start_X+100 Local $GUI_start_listgroup_Y=$GUI_start_Y Local $button_X=$GUI_start_X+80+$GUI_listgroup_width+30 Local $button_Y=$GUI_start_Y Local $button_width=200 Local $button_height=30 ; ; destroying previous group ; GUISetState(@SW_ENABLE,$guiHd) ;if $btnInstallAgent <> 0 Then if $computerList <> 0 Then _GUICtrlListView_UnRegisterSortCallBack($computerList) If NOT _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($computerList)) Then _DebugPrint("Problema _GUICtrlListView_DeleteAllItems") Else _DebugPrint("OK _GUICtrlListView_DeleteAllItems") EndIf If NOT _GUICtrlListView_Destroy (GUICtrlGetHandle($computerList))Then _DebugPrint("Problema _GUICtrlListView_Destroy") Else _DebugPrint("OK _GUICtrlListView_Destroy") EndIf EndIf GUICtrlCreateGroup("User conf", $GUI_start_listgroup_X, $GUI_start_listgroup_Y, $GUI_listgroup_width, $GUI_listgroup_height) $userList = _GUICtrlListView_Create($guiHd, "", $GUI_start_list_X, $GUI_start_list_Y,$GUI_list_width, $GUI_list_height,BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT) ) GUISetState() ; Add columns _GUICtrlListView_AddColumn($userList, "user", 150) _GUICtrlListView_AddColumn($userList, "name", 250) _GUICtrlListView_AddColumn($userList, "Status", 150) _GUICtrlListView_SetItemCount($userList, $numUser) _GUICtrlListView_AddArray($userList, $users) _GUICtrlListView_RegisterSortCallBack($userList) _GUICtrlListView_SortItems ($userList, 1) _GUICtrlListView_SortItems ($userList, 2) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_USERLIST") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($userList)] DLLCall("user32.dll","int","InvalidateRect","hwnd",$guiHd,"int",0,"int",0) EndFunc ; end USER FUNC ;========================= ; ; COMPUTER RELATED FUNCTIONS ; ;========================= Func _ComputerList_create() Local $GUI_start_list_X=$GUI_start_X+110 Local $GUI_start_list_Y=$GUI_start_Y+20 Local $GUI_start_listgroup_X=$GUI_start_X+100 Local $GUI_start_listgroup_Y=$GUI_start_Y Local $button_X=$GUI_start_X+80+$GUI_listgroup_width+30 Local $button_Y=$GUI_start_Y Local $button_width=200 Local $button_height=30 GUISetState(@SW_ENABLE,$guiHd) ; ; destroying previous group ; if $userList <> 0 Then _GUICtrlListView_UnRegisterSortCallBack($userList) _GUICtrlListView_DeleteAllItems($userList) _GUICtrlListView_Destroy ($userList) EndIf GUICtrlCreateGroup("computer conf", $GUI_start_listgroup_X, $GUI_start_listgroup_Y, $GUI_listgroup_width, $GUI_listgroup_height) $computerList = GUICtrlCreateListView("", $GUI_start_list_X, $GUI_start_list_Y, $GUI_list_width, $GUI_list_height,BitOR($LVS_REPORT,$LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetUnicodeFormat($computerList, False) GUISetState() ; Add columns _GUICtrlListView_AddColumn($computerList, "Computer", 150) _GUICtrlListView_AddColumn($computerList, "Status", 150) _GUICtrlListView_SetItemCount($computerList, $numPC) _GUICtrlListView_RegisterSortCallBack($computerList) _GUICtrlListView_SortItems ($computerList, 0) ;this reg is for _GUICtrlListView_SimpleSort GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY_COMPUTERLIST") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($computerList)] _GUICtrlListView_AddArray($computerList, $computer) DLLCall("user32.dll","int","InvalidateRect","hwnd",$guiHd,"int",0,"int",0) EndFunc ;==>Func _crea_lista_computer() ; end COMPUTER FUNC ;=================== ; ; ancillaries ; ;================== Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, ;and @GUI_WINHANDLE would equal $mainwindow $returnStatus=MsgBox(1+$msgboxTop, "GUI Event", "Close?") if $returnStatus = 1 Then GUIDelete() Exit 0 EndIf EndFunc;==>CLOSEClicked Func WM_NOTIFY_USERLIST($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $userList If Not IsHWnd($userList) Then $hWndListView = GUICtrlGetHandle($userList) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->Param:" & @TAB & DllStructGetData($tInfo, "Param")) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; No return value Case $LVN_KEYDOWN ; A key has been pressed $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam) _DebugPrint("$LVN_KEYDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @LF & _ "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags")) ; No return value Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_KILLFOCUS ; The control has lost the input focus _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ;Return 1 ; not to allow the default processing Return 0 ; allow the default processing Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value Case $NM_SETFOCUS ; The control has received the input focus _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_NOTIFY_COMPUTERLIST($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $computerList If Not IsHWnd($computerList) Then $hWndListView = GUICtrlGetHandle($computerList) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->Param:" & @TAB & DllStructGetData($tInfo, "Param")) _GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY_COMPUTERLIST Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 2, 2011 Share Posted February 2, 2011 Why are you creating the computer listview with the native AutoIt control instead of _GuiCtrlListView_Create()? You got it right with the user listview. The UDF functions should generally be used on UDF created controls. Mixing them with native AutoIt controls leads to aggravating weirdness. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
steff Posted February 14, 2011 Author Share Posted February 14, 2011 Thankf for the reply. Infact, using the UDF functions was the right thing to do. 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