Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2554 closed Feature Request (Completed)

UDF - GuiTreeView.au3 - _GUICtrlTreeView_Sort - proposal

Reported by: mlipok Owned by: guinness
Milestone: 3.3.9.25 Component: Standard UDFs
Version: Severity: None
Keywords: Cc:

Description

now is:

Func _GUICtrlTreeView_Sort($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

	Local $hItem, $a_tree
	For $i = 0 To _GUICtrlTreeView_GetCount($hWnd)
		If $i == 0 Then
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $TVI_ROOT, 0, "wparam", "handle", "handle")
		Else
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "handle", "handle")
		EndIf
		If IsArray($a_tree) Then
			ReDim $a_tree[UBound($a_tree) + 1]
		Else
			Dim $a_tree[1]
		EndIf
		$a_tree[UBound($a_tree) - 1] = $hItem
	Next
	If IsArray($a_tree) Then
		Local $hChild, $i_Recursive = 1
		For $i = 0 To UBound($a_tree) - 1
			_SendMessage($hWnd, $TVM_SORTCHILDREN, $i_Recursive, $a_tree[$i], 0, "wparam", "handle") ; sort the items in root
			Do ; sort all the children
				$hChild = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "handle", "handle")
				If $hChild > 0 Then
					_SendMessage($hWnd, $TVM_SORTCHILDREN, $i_Recursive, $hChild, 0, "wparam", "handle")
				EndIf
				$hItem = $hChild
			Until $hItem = 0x00000000
		Next
	EndIf
EndFunc   ;==>_GUICtrlTreeView_Sort

I removed depracted Dim declaration,

By the way I removed it from the inside:

For $ i = 0 This _GUICtrlTreeView_GetCount ($ hWnd)
....
Next

By the way a little sped up.

I checked on a modified example from the documentation:

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Global $hImage, $hStateImage

Func _GUICtrlTreeView_Sort_new($hWnd)
	If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

	Local $hItem, $vItemCount = _GUICtrlTreeView_GetCount($hWnd)
	Local $a_tree[$vItemCount]
	For $i = 0 To $vItemCount -1
		If $i == 0 Then
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $TVI_ROOT, 0, "wparam", "handle", "handle")
		Else
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hItem, 0, "wparam", "handle", "handle")
		EndIf
		$a_tree[$i] = $hItem
	Next
	If IsArray($a_tree) Then
		Local $hChild, $i_Recursive = 1
		For $i = 0 To UBound($a_tree) - 1
			_SendMessage($hWnd, $TVM_SORTCHILDREN, $i_Recursive, $a_tree[$i], 0, "wparam", "handle") ; sort the items in root
			Do ; sort all the children
				$hChild = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem, 0, "wparam", "handle", "handle")
				If $hChild > 0 Then
					_SendMessage($hWnd, $TVM_SORTCHILDREN, $i_Recursive, $hChild, 0, "wparam", "handle")
				EndIf
				$hItem = $hChild
			Until $hItem = 0x00000000
		Next
	EndIf
EndFunc   ;==>_GUICtrlTreeView_Sort

Example()

Func Example()
	Local $hItem[10], $iX = 9, $iY = 29, $hTreeView
	Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

	GUICreate("TreeView Sort", 400, 300)

	$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
	GUISetState()

	_GUICtrlTreeView_BeginUpdate($hTreeView)
	For $x = 0 To 9
		$hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $iX), $hTreeView)
		$iX -= 1
		For $y = 1 To 3
			GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $iY), $hItem[$x])
			$iY -= 1
		Next
	Next
	_GUICtrlTreeView_Expand($hTreeView)
	_GUICtrlTreeView_EndUpdate($hTreeView)

	MsgBox($MB_SYSTEMMODAL, "Information", "Sort")
	_GUICtrlTreeView_Sort_new($hTreeView)
	_GUICtrlTreeView_SelectItem($hTreeView, $hItem[9])

	; Loop until user exits
	Do
	Until GUIGetMsg() = $GUI_EVENT_CLOSE
	GUIDelete()
EndFunc   ;==>Example

_GUICtrlTreeView_Sort_new($hWnd) is a modified _GUICtrlTreeView_Sort($hWnd)

Please consider changing the standard UDF.

Attachments (0)

Change History (4)

comment:1 Changed 10 years ago by TicketCleanup

  • Version 3.3.9.23 deleted

Automatic ticket cleanup.

comment:2 Changed 10 years ago by guinness

  • Milestone set to 3.3.9.25
  • Owner set to guinness
  • Resolution set to Completed
  • Status changed from new to closed

Changed by revision [9244] in version: 3.3.9.25

comment:3 Changed 10 years ago by guinness

The function has been modified heavily from your proposal. Thanks for bringing it to our attention.

comment:4 Changed 10 years ago by mlipok

You're welcome
If I find something else that will let you know ;)

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain guinness.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.