Simple (hopefully) questions about treeview control.

Started by Elias Montoya, September 26, 2013, 01:14:02 PM

Previous topic - Next topic

Elias Montoya

 Hello,

I have 3 questions i have regarding firefly's functions for a treeview:


  • Is there a firefly-based way to see what item was double-clicked? (my method currently works but traps the same message in the empty area of the control)
  • Is there a firefly-based way to get the parent node of a treeview item?
  • Is there a firefly-based way of getting a list of child nodes for a node?

I have very little knowledge about the treeview item, any pointers will be much appreciated.

:)
Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Paul Squires

Here is code that I use to handle the treeviews in the FireFly Project Explorer (I removed some stuff but you should get the general idea). This should help with the doubleclick and rightclick:

'------------------------------------------------------------------------------------------------------------------------
Function FRMEXPLORER_CUSTOM ( _
                            hWndForm      As Dword, _  ' handle of Form
                            wMsg          As Long,  _  ' type of message
                            wParam        As Dword, _  ' first message parameter
                            lParam        As Long   _  ' second message parameter
                            ) As Long

   Local pForm  As FORM_TYPE Ptr
   Local ht     As TV_HITTESTINFO
   Local lpTV   As NM_TREEVIEW Ptr
   Local tItem  As TV_ITEM             
   Local wID    As Long
   Local hPopup As Long
     
   
   Select Case wMsg

      Case %WM_CONTEXTMENU ' Right click or Shift-F10 occured
        ' We got a right click
         ht.pt.x = LoWrd(lParam)
         ht.pt.y = HiWrd(lParam)
       
         If ScreenToClient( HWND_FRMEXPLORER_TREEVIEW1, ht.pt) Then
            SendMessage HWND_FRMEXPLORER_TREEVIEW1, %TVM_HITTEST, 0, VarPtr(ht)
            If ht.hItem Then
               TreeView_Select HWND_FRMEXPLORER_TREEVIEW1, ht.hItem, %TVGN_CARET
               hPopUp = ExplorerPopUpMenu( ht.hItem )
               TrackPopupMenu hPopUp, 0, LoWrd(lParam), HiWrd(lParam), 0, hwndForm, ByVal %Null
            End If   
         End If


     Case %WM_NOTIFY
        'determine which control is sending the notification
         Select Case LoWrd(wParam)
           Case IDC_FRMEXPLORER_TREEVIEW1, IDC_FRMEXPLORER_TREEVIEW2
             lpTV = lParam
             
             '// DOUBLE_CLICK //       
             If @lpTV.hdr.Code = %NM_DBLCLK Then   
             
                ' Display the code or form depending on which node is selected. That
                ' function is also used to respond to clicks on the Explorer Toolbar.
                DoViewFormOrCode -1
                Exit Function
                               
             End If
                 
             ' If the node is expanding/collapsing then check to see if it is the
             ' Forms or Modules nodes. If they are, then change the icons to show OPEN.
             If @lpTV.hdr.Code = %TVN_ITEMEXPANDED Then 
                 ' Set the Treeview's new selected icons
                 ' The itemNew structure contains the handle of the TreeView line
                 ' that is sending the notification message.
                 If (@lpTV.itemNew.hItem = g.hFormNode) Or (@lpTV.itemNew.hItem = g.hModuleNode) Or _
                    (@lpTV.itemNew.hItem = g.hResourceNode) Or (@lpTV.itemNew.hItem = g.hSpecialNode) Then
                     
                     tItem.hitem = @lpTV.itemNew.hItem
                     tItem.mask = %TVIF_IMAGE Or %TVIF_SELECTEDIMAGE
                     
                     If @lpTV.Action = %TVE_EXPAND Then
                        tItem.iImage = g.Explorer_OpenIcon
                        tItem.iSelectedImage = g.Explorer_OpenIcon
                     End If   
                     
                     If @lpTV.Action = %TVE_COLLAPSE Then
                        tItem.iImage = g.Explorer_ClosedIcon
                        tItem.iSelectedImage = g.Explorer_ClosedIcon
                     End If
                     
                     TreeView_SetItem HWND_FRMEXPLORER_TREEVIEW1, tItem   
                 
                 End If   
             End If
             
         End Select
       
   End Select
   
End Function


Paul Squires
PlanetSquires Software

Paul Squires

Here is code to iterate all child nodes off of the specified node (I got this from Paul Noble a very long time ago)  :)

'//
'//  Calculates the number of immediate children under item <hUnder> in
'//  treeview <hTree>
'//
Function TVW_NodeCountUnder( ByVal hTree As Long, _
                             ByVal hUnder As Long _
                             ) As Long

   Local hItem  As Long
   Local mCount As Long

   'Locate the first child item...
   hItem = TreeView_GetNextItem( hTree, hUnder, %TVGN_CHILD )

   'Iterate over any items found...
   While hItem

      Incr mCount
      hItem = TreeView_GetNextItem( hTree, hItem, %TVGN_NEXT )

   Wend

   Function = mCount

End Function


Paul Squires
PlanetSquires Software

Paul Squires

To get the Parent node (check out all of the functions in Jose's TreeViewCtrl.inc file):

' ========================================================================================
' Retrieves the parent item of the specified tree-view item.
' ========================================================================================
FUNCTION TreeView_GetParent (BYVAL hwndTV AS DWORD, BYVAL hItem AS DWORD) AS DWORD
   FUNCTION = TreeView_GetNextItem(hwndTV, hItem, %TVGN_PARENT)
END FUNCTION

Paul Squires
PlanetSquires Software

Elias Montoya

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.