treeview

Started by paulDiagnos, June 19, 2008, 07:20:51 AM

Previous topic - Next topic

paulDiagnos

me once again, (you can tell im starting a new project)

Treeviews, is there any simple way (just like listview) of getting the text of a selected item.

I have looked through the help but cant quite see anything of help other than

FF_TreeView_GetText, but there doesnt seem to be a get selected item that would be very useful.

even when i try and pop in the hitem myself this doesnt seem to work

sText = FF_TreeView_GetText( hwnd_scrncapt_CaptureTreeView,1)

TechSupport

Hi Paul,

You would need to use the TreeView_GetSelection macro. There are many functions defined in CommCtrl.inc (PowerBASIC's WinAPI directory) that you can use with FireFly.

hItem = TreeView_GetSelection( hWndTreeview )


paulDiagnos

Brilliant i new it would be something simple.
thanks for the clue

Paul.

paulDiagnos

#3
Ok Manages to do that.. next step.. sorry.

SetFocus(HWND_scrncapt_CaptureTreeView)
TreeView_Select(HWND_scrncapt_CaptureTreeView,X,%tvgn_caret)
TreeView_EditLabel(HWND_scrncapt_CaptureTreeView,x)


This now lets me type stuff in to rename a section etc, but how do i get the text to stay how it it.

the only way i can exit the edit mode is by esc or click somewhere else then the text is lost.

i have tried getting the treeview to except carrage returns but alass this doesnt work.


ha ok found it....

'------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_CAPTURETREEVIEW_TVN_ENDLABELEDIT ( _
                                                   ControlIndex  As Long,            _  ' index in Control Array
                                                   hWndForm      As Dword,           _  ' handle of Form
                                                   hWndControl   As Dword,           _  ' handle of Control
                                                   ByVal lpTVDI  As TV_DISPINFO Ptr  _  ' pointer to TV_DISPINFO
                                                   ) As Long
MsgBox "ok"
End Function


just use firefly !!!





Paul.

paulDiagnos

Ok really am stuck now

any ideas on how to know when someone has hit enter.
I tried the following but no such luck :

'------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_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


        If wMsg = 135 And wparam = %VK_RETURN Then

MsgBox "enter pushed. "

End If
End Function


and

'------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_CAPTURETREEVIEW_CUSTOM ( _
                                         ControlIndex  As Long,  _  ' index in Control Array
                                         hWndForm      As Dword, _  ' handle of Form
                                         hWndControl   As Dword, _  ' handle of Control
                                         wMsg          As Long,  _  ' type of message
                                         wParam        As Dword, _  ' first message parameter
                                         lParam        As Long   _  ' second message parameter
                                         ) As Long
If gTreeHandle = hWndControl Then
               If wMsg = 135 And wparam = %VK_RETURN Then

MsgBox "enter pushed. "




End If
End If
End Function
'------------------------------------------------------------------------------------------------------------------------
Function SCRNCAPT_CAPTURETREEVIEW_TVN_BEGINLABELEDIT ( _
                                                     ControlIndex  As Long,            _  ' index in Control Array
                                                     hWndForm      As Dword,           _  ' handle of Form
                                                     hWndControl   As Dword,           _  ' handle of Control
                                                     ByVal lpTVDI  As TV_DISPINFO Ptr  _  ' pointer to TV_DISPINFO
                                                     ) As Long     
                                                     
gTreeHandle= hWndControl

End Function



but not a lot of luck

TechSupport

Hi Paul,

Here is code directly from FireFly3 that deals with editing Treeview item text and the ENTER key. Take from it the relevant parts for yourself. The stuff named "snippets" wouldn't be useful to you.




Function FF_SubClassStart( ByVal hWndControl As Dword, _
                           ByVal hNewProc As Dword _
                           ) As Long
   
   Local hOrigProc As Dword
   
   hOrigProc = SetWindowLong( hWndControl, %GWL_WNDPROC, hNewProc )
   SetWindowLong hWndControl, %GWL_USERDATA, hOrigProc
           
End Function

Function FF_SubClassEnd( ByVal hWndControl As Dword ) As Long

   Local hOrigProc As Dword
   
   hOrigProc = GetWindowLong( hWndControl, %GWL_USERDATA )
   SetWindowLong hWndControl, %GWL_WNDPROC, hOrigProc

End Function

'--------------------------------------------------------------------------------
Function FRMSNIPPETS_TREEVIEW1_TVN_BEGINLABELEDIT ( _
                                                  ControlIndex  As Long,            _  ' index in Control Array
                                                  hWndForm      As Dword,           _  ' handle of Form
                                                  hWndControl   As Dword,           _  ' handle of Control
                                                  ByVal lpTVDI  As TV_DISPINFO Ptr  _  ' pointer to TV_DISPINFO
                                                  ) As Long

   ' If an item is selected then start the edit process
   'Local hTreeItem As Dword
   Local hEditControl As Dword
   
   hEditControl = TreeView_GetEditControl( HWND_FRMSNIPPETS_TREEVIEW1 )
   ' Subclass the edit control
   If hEditControl Then
      FF_SubClassStart hEditControl, CodePtr(TreeView_NewEditProc)
   End If
                                 

End Function


'--------------------------------------------------------------------------------
Function FRMSNIPPETS_TREEVIEW1_TVN_ENDLABELEDIT ( _
                                                ControlIndex  As Long,            _  ' index in Control Array
                                                hWndForm      As Dword,           _  ' handle of Form
                                                hWndControl   As Dword,           _  ' handle of Control
                                                ByVal lpTVDI  As TV_DISPINFO Ptr  _  ' pointer to TV_DISPINFO
                                                ) As Long

   Local pSnippet As SNIPPET_TYPE Ptr
   Local tItem    As TV_ITEM
   Local zText    As Asciiz Ptr
   
   ' Label is finished being edited. Update the Snippet information
   @lpTVDI.item.mask = %TVIF_PARAM Or %TVIF_TEXT Or %TVIF_HANDLE         
   TreeView_GetItem hWndControl, tItem
   
   pSnippet = @lpTVDI.item.lParam
   zText    = @lpTVDI.item.pszText
   
   ' Don't allow zero-length text
   If Len(@zText) = 0 Then
      Function = 1: Exit Function
   End If
     
   If pSnippet Then
      MemString @pSnippet.zName, @zText
      FF_TreeView_SetText hWndControl, @lpTVDI.item.hItem, @zText
      @pSnippet.IsDirty = %TRUE
   End If
   
End Function



Function TreeView_NewEditProc( _
                            ByVal hWndControl   As Long,  _  ' handle of TreeView Edit control
                            ByVal wMsg          As Long,  _  ' type of message
                            ByVal wParam        As Long,  _  ' first message parameter
                            ByVal lParam        As Long   _  ' second message parameter
                            ) As Long


   Local hOldProc  As Dword
   
   Select Case wMsg
     
      Case %WM_GETDLGCODE
        Function = %DLGC_WANTALLKEYS
        Exit Function

      Case %WM_DESTROY
         ' Reset any subclass treeview edit control
         FF_SubClassEnd hWndControl
         
      Case Else
               
   End Select

   hOldProc = GetWindowLong( hWndControl, %GWL_USERDATA )
   Function = CallWindowProc( hOldProc, hWndControl, wMsg, wParam, lParam )
   
End Function




TechSupport

Oh, and you can manually initiate a label edit when someone double-clicks a treeview item using code like the following:


Function FRMSNIPPETS_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 pNMTV As NM_TREEVIEW Ptr
  Local pNSC  As NMSETINFO Ptr
  Local hTreeItem As Long
  Local pSnippet  As SNIPPET_TYPE Ptr
 
 
  Select Case wMsg
     
     Case %WM_NOTIFY
            pNMTV = lParam
            pNSC  = lParam
           
            Select Case @pNMTV.hdr.idfrom
           
               Case IDC_FRMSNIPPETS_TREEVIEW1  ' notify message from the listview control
                     
                  Select Case @pNMTV.hdr.code

                     Case %NM_CLICK    'left click         
                           
                     Case %NM_DBLCLK   'left double-click
                        hTreeItem = FF_TreeView_GetSelection( HWND_FRMSNIPPETS_TREEVIEW1 )
                        If hTreeItem > 0 Then TreeView_EditLabel( HWND_FRMSNIPPETS_TREEVIEW1, hTreeItem )
                             
                     Case %NM_RCLICK   ' right click

                     Case %NM_RDBLCLK   'right double-click

                 End Select

...
...
...



paulDiagnos

Works a treat!

So i take it the subclass things are away of getting firefly to receive all the messages in  a designated function ?