Modify

Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#4039 closed Bug (Fixed)

Bug with _GUICtrlTreeView_Delete

Reported by: Kanashius Owned by: J-Paul Mesnage
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 by J-Paul Mesnage, 12 months ago

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

comment:2 by J-Paul Mesnage, 12 months ago

Milestone: 3.3.17.0
Owner: set to J-Paul Mesnage
Resolution: Fixed
Status: newclosed

Fixed by revision [13093] in version: 3.3.17.0

comment:3 by J-Paul Mesnage, 12 months ago

Finally I get it

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.