I'm trying to return information from all the items that are checked in the treeview. I would like to return if the parent is checked and any children that are checked if the parent isnt checked, either postition (i.e Parent2|Child3|Sibling1 or 2,3,1) or text would work. Ive been trying various "_GUICtrlTree..." functions with little success.
Any direction would be greatly appreciated.
I did find this gem that automaticaly checks child items if the parent is selected. Much respect to Melba23 and Authenticity for that.
http://www.autoitscript.com/forum/topic/...tparenthandle__fromsearch__1#e
I've posted the code that I'm working on.
Plain Text
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> #include <ButtonConstants.au3> Local $hGUI, $Tree, $hTree, $hItems[40][2] = [[0]] $Form1_1 = GUICreate("Form1", 616, 532, 192, 124) $string = StringSplit("parent1,child1,child2,child3,sibling1,parent2,child1,child2,child3,sibling1",",") $button1 = GUICtrlCreateButton("Select", 40, 200, 100, 50) $List1 = GUICtrlCreateTreeView(40, 260, 530, 200, BitOR($GUI_SS_DEFAULT_TREEVIEW,$TVS_EDITLABELS,$TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) $hTree = GUICtrlGetHandle($List1) $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, "shell32.dll", 8) _GUIImageList_AddIcon($hImage, "shell32.dll", 166) _GUICtrlTreeView_SetNormalImageList($List1, $hImage) _GUICtrlTreeView_BeginUpdate($List1) For $x = 0 To ubound($string) - 1 if StringInStr($string[$x],"parent",0) > 0 Then $tree_disk = _GUICtrlTreeView_Add($List1, 0, $string[$x], 0) EndIf if StringInStr($string[$x],"child",0) > 0 Then $tree_Part = _GUICtrlTreeView_AddChild($List1, $tree_disk,$string[$x], 1,1) EndIf if StringInStr($string[$x],"sibling",0) > 0 Then $tree_logical = _GUICtrlTreeView_AddChild($List1,$tree_Part, $string[$x], 1, 1) EndIf Next _GUICtrlTreeView_EndUpdate($List1) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button1 MsgBox(0,"",_GUICtrlTreeView_GetCount($hTree)) EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $iPos, $iX, $iY, $tPt, $iHitTest, $fWasChecked Local $hItem $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTree Switch $iCode Case $NM_CLICK $iPos = _WinAPI_GetMessagePos() $iX = BitAND($iPos, 0xFFFF) $iY = BitShift($iPos, 16) $tPt = DllStructCreate($tagPOINT) DllStructSetData($tPt, "X", $iX) DllStructSetData($tPt, "Y", $iY) _WinAPI_ScreenToClient($hTree, $tPt) $iX = DllStructGetData($tPt, "X") $iY = DllStructGetData($tPt, "Y") $tTVHTInfo = _GUICtrlTreeView_HitTestEx($hTree, $iX, $iY) If DllStructGetData($tTVHTInfo, "Flags") = $TVHT_ONITEMSTATEICON Then $hItem = DllStructGetData($tTVHTInfo, "Item") $fWasChecked = _GUICtrlTreeView_GetChecked($hTree, $hItem) If $fWasChecked Then _GUICtrlTreeView_BeginUpdate($hTree) _Uncheck($hItem) _GUICtrlTreeView_EndUpdate($hTree) Else _GUICtrlTreeView_BeginUpdate($hTree) _CallItemFunc($hItem) _Check($hItem) _GUICtrlTreeView_EndUpdate($hTree) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _Uncheck($hItem) Local $hParent, $hItemCur, $iLevel $iLevel = _GUICtrlTreeView_Level($hTree, $hItem) $hItemCur = _GUICtrlTreeView_GetFirstChild($hTree, $hItem) While $hItemCur And _GUICtrlTreeView_Level($hTree, $hItemCur) > $iLevel _GUICtrlTreeView_SetChecked($hTree, $hItemCur, False) $hItemCur = _GUICtrlTreeView_GetNext($hTree, $hItemCur) WEnd $hParent = _GUICtrlTreeView_GetParentHandle($hTree, $hItem) If $hParent Then While $hParent If $hParent <> $hItem Then _GUICtrlTreeView_SetChecked($hTree, $hParent, False) $hParent = _GUICtrlTreeView_GetParentHandle($hTree, $hParent) WEnd EndIf EndFunc Func _Check($hItem) Local $hParent, $hItemCur, $iLevel $iLevel = _GUICtrlTreeView_Level($hTree, $hItem) $hItemCur = _GUICtrlTreeView_GetFirstChild($hTree, $hItem) While $hItemCur And _GUICtrlTreeView_Level($hTree, $hItemCur) > $iLevel _GUICtrlTreeView_SetChecked($hTree, $hItemCur) _CallItemFunc($hItemCur) $hItemCur = _GUICtrlTreeView_GetNext($hTree, $hItemCur) WEnd $hParent = _GUICtrlTreeView_GetParentHandle($hTree, $hItem) While $hParent $hItemCur = _GUICtrlTreeView_GetFirstChild($hTree, $hParent) While $hItemCur If Not _GUICtrlTreeView_GetChecked($hTree, $hItemCur) And $hItemCur <> $hItem Then ExitLoop 2 $hItemCur = _GUICtrlTreeView_GetNextSibling($hTree, $hItemCur) WEnd _GUICtrlTreeView_SetChecked($hTree, $hParent) _CallItemFunc($hParent) $hParent = _GUICtrlTreeView_GetParentHandle($hTree, $hParent) WEnd EndFunc Func _WinAPI_GetMessagePos() Local $aResult = DllCall("user32.dll", "uint", "GetMessagePos") If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func _CallItemFunc($hItem) For $i = 1 To $hItems[0][0] If $hItem = $hItems[$i][0] Then Call($hItems[$i][1]) ExitLoop EndIf Next EndFunc





