Date: 02-16-2022
Return to Index
created by gbSnippets
'If you've saved the handle to a node for later use, it's possible that the
'node might have been deleted before the handle is used. This snippet shows
'how to check whether a handle points to a valid node item.
'Primary Code:
'The %TVM_GetItem API is send to the Treeview control, asking for information
'about the stored handle. If the message succeeds (node exists), the message
'returns a TRUE value, of FALSE if it fails.
iResult = SendMessage(hTree, %TVM_GetItem, 0, TVP)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "commctrl.inc"
Global hDlg As DWord, hNode As DWord, hTree As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "TreeView",200,200,200,250, %WS_SysMenu, 0 To hDlg
'create control
Control Add TreeView, hDlg, 100, "", 10,10,130,125
Control Handle hDlg, 100 To hTree
Control Add Button, hDlg, 111, "Get Handle of Selection", 10, 150, 180, 20
Control Add Button, hDlg, 112, "Kill Selected", 10, 180, 180, 20
Control Add Button, hDlg, 113, "Send TVM_GetItem Using Handle", 10, 210, 180, 20
'add items hdlg,id&,hPrnt,hIAftr,image&,selimage&,txt$ To hItem
TreeView Insert Item hDlg, 100, 0, %TVI_Last, 1,1,"One" To hNode
TreeView Insert Item hDlg, 100, 0, %TVI_Last, 2,2,"Two" To hNode
TreeView Insert Item hDlg, 100, 0, %TVI_Last, 3,3,"Three" To hNode
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case 111 : TreeView Get Select hDlg, 100 To hNode : ? Str$(hNode)
Case 112 : TreeView Delete hDlg, 100, hNode
Case 113 : ? Str$(NodeExists)
End Select
End Select
End Function
Function NodeExists() As Long
Local TV As TV_Item, iResult As Long
TV.Hitem = hNode
Function = SendMessage(hTree, %TVM_GetItem, 0, ByVal VarPTR(TV))
End Function
'gbs_00608
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm