Modify

Opened 4 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#4039 closed Bug (Fixed)

Bug with _GUICtrlTreeView_Delete

Reported by: Kanashius Owned by: Jpm
Milestone: 3.3.17.0 Component: Standard UDFs
Version: 3.3.16.1 Severity: None
Keywords: TreeView, _GUICtrlTreeView_Delete Cc:

Description

The _GUICtrlTreeView_Delete deletes random controls instead of the provided item using x64 AutoIt.

The issue already came up and was fixed, if a ControlID was provided, but it was overlooked to fix it for ControlHandles, too.

Comment in the UDF to that:

; Danyfirex founding
; If We Use IsHWnd It will always return false. So You will always call _GUICtrlTreeView_GetItemHandle and You will get the GUICtrlGetHandle issue that happens randomly
; So let's use IsPtr and remove GUICtrlDelete So we can always delete using the Control Handle.

As it already came up as a Bug, I did not write an additional Example for that.

Proposed fix to change

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: re-written by Holger Kotsch, re-written again by Gary Frost
;                  $hItem = Null by Jpm
; ===============================================================================================================================
Func _GUICtrlTreeView_Delete($hWnd, $hItem = Null)
	If IsHWnd($hWnd) Then
		If $hItem = Null Then
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
			If $hItem <> 0x00000000 Then Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
			Return False
		Else
			If Not IsHWnd($hItem) Then $hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
			If GUICtrlDelete($hItem) Then Return True
			Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
		EndIf
	Else
		If $hItem = Null Then
			$hItem = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
			If $hItem <> 0x00000000 Then Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
			Return False
		Else
			; Danyfirex founding
			; If We Use IsHWnd It will always return false. So You will always call _GUICtrlTreeView_GetItemHandle and You will get the GUICtrlGetHandle issue that happens randomly
			; So let's use IsPtr and remove GUICtrlDelete So we can always delete using the Control Handle.
			If Not IsPtr($hItem) Then
				$hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
			Else
				SetExtended(1)
			EndIf
			Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
		EndIf
	EndIf
EndFunc   ;==>_GUICtrlTreeView_Delete

into

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: re-written by Holger Kotsch, re-written again by Gary Frost
;                  $hItem = Null by Jpm
; ===============================================================================================================================
Func _GUICtrlTreeView_Delete($hWnd, $hItem = Null)
	If IsHWnd($hWnd) Then
		If $hItem = Null Then
			$hItem = _SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0, 0, "wparam", "handle", "handle")
			If $hItem <> 0x00000000 Then Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
			Return False
		Else
			If Not IsPtr($hItem) Then 
				$hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
			EndIf
			Return _SendMessage($hWnd, $TVM_DELETEITEM, 0, $hItem, 0, "wparam", "handle", "hwnd") <> 0
		EndIf
	Else
		If $hItem = Null Then
			$hItem = GUICtrlSendMsg($hWnd, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
			If $hItem <> 0x00000000 Then Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
			Return False
		Else
			; Danyfirex founding
			; If We Use IsHWnd It will always return false. So You will always call _GUICtrlTreeView_GetItemHandle and You will get the GUICtrlGetHandle issue that happens randomly
			; So let's use IsPtr and remove GUICtrlDelete So we can always delete using the Control Handle.
			If Not IsPtr($hItem) Then
				$hItem = _GUICtrlTreeView_GetItemHandle($hWnd, $hItem)
			Else
				SetExtended(1)
			EndIf
			Return GUICtrlSendMsg($hWnd, $TVM_DELETEITEM, 0, $hItem) <> 0
		EndIf
	EndIf
EndFunc   ;==>_GUICtrlTreeView_Delete

(Changed lines: 13,14,15(,16))

The problem came up in https://www.autoitscript.com/forum/topic/173926-fileexplorer-treeview-and-listview-treelistexplorer/page/3/#findComment-1541943

Attachments (0)

Change History (3)

comment:1 Changed 3 weeks ago by Jpm

Can you please post a repro script as I don't understand the pointed post
Thanks

comment:2 Changed 3 weeks ago by Jpm

  • Milestone set to 3.3.17.0
  • Owner set to Jpm
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [13093] in version: 3.3.17.0

comment:3 Changed 3 weeks ago by Jpm

Finally I get it

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 Jpm.
Author


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

 
Note: See TracTickets for help on using tickets.