Date: 02-16-2022
Return to Index
created by gbSnippets
'The PowerBASIC DDT commands allow us to loop through all children of a node.
'Primary Code:
'walks through (selects) children of specified Node
'returns last child (PowerBASIC has get first, next, previous commands)
'returns 0 if no children
Function WalkThroughChildrenOfNode(ByVal hNode as Dword) as Dword
TreeView Get Child hDlg, %IDC_TreeView, hNode To hNode
While hNode
Function = hNode
TreeView Select hDlg, %IDC_TreeView, hNode : Sleep 300 'for demo only - selection/pause is optional
TreeView Get Next hDlg, %IDC_TreeView, hNode To hNode
Wend
End Function
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_TreeView = 100 : %IDC_Button = 200
Global hDlg As Dword
Function PBMain() As Long
Local hItem As Dword, hTemp As Dword, hTemp2 As Dword, hTemp3 As Dword
Dialog New Pixels, 0, "TreeView",200,200,155,250, %WS_SysMenu, 0 To hDlg
Control Add TreeView, hDlg, %IDC_TreeView, "", 10,10,130,200
Control Add Button, hDlg, %IDC_Button,"Start", 25,220,95,20
TreeView Insert Item hDlg, %IDC_TreeView, 0, %TVI_Last, 0,0,"Root" To hItem
TreeView Insert Item hDlg, %IDC_TreeView, hItem, %TVI_Last, 0,0,"Mother" To hTemp
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Dan" To hTemp2
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Bob" To hTemp3
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp, %True
TreeView Insert Item hDlg, %IDC_TreeView, hTemp3, %TVI_Last, 0,0,"Foot" To hTemp2
TreeView Insert Item hDlg, %IDC_TreeView, hTemp3, %TVI_Last, 0,0,"Arm" To hTemp2
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp3, %True
TreeView Insert Item hDlg, %IDC_TreeView, hItem, %TVI_Last, 0,0,"Father" To hTemp
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Helen" To hTemp2
TreeView Insert Item hDlg, %IDC_TreeView, hTemp, %TVI_Last, 0,0,"Any" To hTemp3
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp, %True
TreeView Insert Item hDlg, %IDC_TreeView, hTemp3, %TVI_Last, 0,0,"Leg" To hTemp2
TreeView Insert Item hDlg, %IDC_TreeView, hTemp3, %TVI_Last, 0,0,"Finger" To hTemp2
TreeView Set Expanded hDlg, %IDC_TreeView, hTemp3, %True
TreeView Set Expanded hDlg, %IDC_TreeView, hItem, %True
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hNode As Dword, temp$
If CB.Msg = %WM_Command AND CB.Ctl = %IDC_Button Then
TreeView Get Select CB.Hndl, %IDC_TreeView To hNode
hNode = WalkThroughChildrenOfNode (hNode)
If hNode Then TreeView Get Text hDlg, %IDC_TreeView, hNode To temp$ : MsgBox temp$
End If
End Function
Function WalkThroughChildrenOfNode(ByVal hNode as Dword) as Dword
'walks through (selects) children of specified Node
'returns last child (PowerBASIC has get first, next, previous commands)
'returns 0 if no children
TreeView Get Child hDlg, %IDC_TreeView, hNode To hNode
While hNode
Function = hNode
TreeView Select hDlg, %IDC_TreeView, hNode : Sleep 300 'for demo only - selection/pause is optional
TreeView Get Next hDlg, %IDC_TreeView, hNode To hNode
Wend
End Function
'gbs_00276
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm