Announcement

Collapse
No announcement yet.

Edit Node in TreeView

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edit Node in TreeView

    Can Someone Please explain why and help with a solution to the following:

    In the treeview control, when a node is clicked, it enters an edit mode, doing the %tvn_beginlabeledit and then wait until the node is edited before doing the %tvn_endlabeledit which is correct.

    However, when the edit node process is started with a right click and " Edit Selected Node" is selected, then it does the %tvn_beginlabeledit and then do not wait for the editing, but goes directly into %tvn_endlabeledit ???????

    I suspect that the selection from the menu causes an extra "click" and/or command, but how do I detect it? and how is it prevented?

    Also how can the "edit the node" part be disabled when clicking on it? I only want to edit the node when it is selected from the menu
    Code:
    #Compile Exe
    #Dim All
    
    '------------------------------------------------------------------------------
    '   ** Includes **
    '------------------------------------------------------------------------------
    %USEMACROS = 1
    #If Not %def(%WINAPI)
        #Include "WIN32API.INC"
    #EndIf
    #If Not %def(%COMMCTRL_INC)
        #Include "COMMCTRL.INC"
    #EndIf
    #Include "PBForms.INC"
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Constants **
    '------------------------------------------------------------------------------
    #PBForms Begin Constants
    %IDR_IMGFILE1  =  102
    %IDD_DIALOG1   =  101
    %IDC_TOOLBAR   = 1001
    %IDC_TREEVIEW  = 1002
    
    %ITV_INSCHILD      = 3031     ' Insert Child Node
    %ITV_INSBEFORE     = 3032     ' Insert Node Before
    %ITV_INSAFTER      = 3033     ' Insert Node After
    %ITV_EDNODE        = 3034     ' Edit Selected  Node
    %ITV_DELNODE       = 3035     ' Delete Selected  Node
    %ITV_UNDO          = 3036     ' Undo last action
    %ITV_MVUP          = 3037     ' Move Up
    %ITV_MVDOWN        = 3038     ' Move Down
    %ITV_MVLEFT        = 3039     ' Move Left
    %ITV_MVRIGHT       = 3040     ' Move Right
    %ITV_MVHELP        = 3041     ' Help with Drag-Drop
    %ITV_SRTSUB        = 3042     ' Sort SubTree
    %ITV_SRTTREE       = 3043     ' Sort Total Tree
    %ITV_COLSUB        = 3044     ' Collapse SubTree
    %ITV_COLTREE       = 3045     ' Collapse Total Tree
    %ITV_EXPSUB        = 3046     ' Expand SubTree
    %ITV_EXPTREE       = 3047     ' Expand Total Tree
    %ITV_SUBSTATS      = 3048     ' SubTree Statistics
    %maxlabellength    = 30       'max characters that can be entered when editing a label
    
    '------------------------------------------------------------------------------
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Global Type structure - used instead of globals - passed to every routine that use it
    '------------------------------------------------------------------------------
    Type GlobVar
        hTree       As Dword            ' Tree View Control Handle
        hDlg        As Dword            ' Handle to Main Dialog
        hPopM       As Long             ' TreeView Popup Menu Handle
        tEdsbcls    As Dword            ' TreeView Editor subclass
        hNode       As Dword            ' Handle to Node in TreeView
    End Type
    '------------------------------------------------------------------------------
    
    '--------------------------------------------------------------------
    ' Globals
    '--------------------------------------------------------------------
    Global gv As GlobVar
    '------------------------------------------------------------------------------
    '   ** Declarations **
    '------------------------------------------------------------------------------
    Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
    Declare CallBack Function ShowDIALOG1Proc()
    Declare Function SampleTreeView(ByVal hDlg As Dword, ByVal lID As Long, _
                            ByVal lCount As Long) As Long
    Declare Function SampleTreeViewInsertItem(ByVal hTree As Dword, ByVal hParent As _
                                        Dword, sItem As String) As Long
    Declare Function TrackPopup( ByVal hDlg As Long, ByVal hSubMenu As Long, ByVal nFlags As Long ) As Long
    Declare Function treevieweditproc(ByVal hctl As Long, ByVal msg As Long, _
                              ByVal wparam As Long, ByVal lparam As Long) As Long
    
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Main Application Entry Point **
    '------------------------------------------------------------------------------
    Function PBMain()
    
        PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or _
            %ICC_INTERNET_CLASSES)
    
    
        ShowDIALOG1 %HWND_DESKTOP
    
    End Function
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** Dialogs **
    '------------------------------------------------------------------------------
    Function ShowDIALOG1(ByVal hParent As Dword) As Long
        Local lRslt  As Long
    
        Local hDlg   As Dword
        Local hFont1 As Dword
        Local hFont2 As Dword
        Local hFont3 As Dword
    
        Dialog New hParent, "  Test TreeView", 31, 63, 662, 426, %ws_popup Or %ws_border _
            Or %ws_dlgframe Or %ws_thickframe Or %ws_caption Or %ws_sysmenu Or _
            %ws_minimizebox Or %ws_maximizebox Or %ws_clipsiblings Or _
            %ws_visible Or %ds_modalframe Or %ds_3dlook Or %ds_nofailcreate Or _
            %ds_setfont, %ws_ex_clientedge Or %ws_ex_staticedge Or _
            %ws_ex_windowedge Or %ws_ex_acceptfiles Or %ws_ex_controlparent Or _
            %ws_ex_left Or %ws_ex_ltrreading Or %ws_ex_rightscrollbar, To hDlg
    
        Control Add "SysTreeView32", hDlg, %IDC_TREEVIEW, "TreeView", 0, 35, 100, _
            390, %ws_child Or %ws_visible Or %ws_tabstop Or %tvs_hasbuttons Or _
            %tvs_haslines Or %tvs_linesatroot Or %tvs_editlabels Or _
            %tvs_showselalways Or %tvs_trackselect Or %tvs_infotip, _
            %ws_ex_clientedge Or %ws_ex_staticedge Or %ws_ex_dlgmodalframe Or _
            %ws_ex_acceptfiles Or %ws_ex_left Or %ws_ex_ltrreading Or _
            %ws_ex_rightscrollbar
    
    
        Control Send hDlg, %IDC_TREEVIEW, %TVM_SETTEXTCOLOR, 0, %black
        Control Send hDlg, %IDC_TREEVIEW, %TVM_SETBKCOLOR, 0, RGB(220, 241, 220)
    
        SampleTreeView hDlg, %IDC_TREEVIEW, 3
    
        Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
    
    
        Function = lRslt
    End Function
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    '   ** CallBacks **
    '------------------------------------------------------------------------------
    CallBack Function ShowDIALOG1Proc()
        Local pNMHDR As NMHDR Ptr
        Local ptvdi As tv_dispinfo Ptr
        Local i As Long
        Local htvedit&
        Local txt$
    
    
        Select Case As Long Cb.Msg
            Case %wm_initdialog
                ' Initialization handler
                DragAcceptFiles Cb.Hndl, %TRUE
                
                ' get and store the control and Dialog handles
                gv.hTree = GetDlgItem(Cb.Hndl, %IDC_TREEVIEW)
                gv.hDlg = Cb.Hndl
    
                ' TreeView Popup Menu
                Menu New PopUp To gv.hPopM
                Menu Add String, gv.hPopM , "Insert Child Node", %ITV_INSCHILD, %mf_enabled
                Menu Add String, gv.hPopM , "Insert Node Before", %ITV_INSBEFORE, %mf_enabled
                Menu Add String, gv.hPopM , "Insert Node After", %ITV_INSAFTER, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "&Edit Selected Node", %ITV_EDNODE, %mf_enabled
                Menu Add String, gv.hPopM , "Delete Selected Node", %ITV_DELNODE, %mf_enabled
                Menu Add String, gv.hPopM , "Undo last Action"  & $Tab & "CTRL+Z", %ITV_UNDO, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "Move Up", %ITV_MVUP, %mf_enabled
                Menu Add String, gv.hPopM , "Move Down", %ITV_MVDOWN, %mf_enabled
                Menu Add String, gv.hPopM , "Move Left", %ITV_MVLEFT, %mf_enabled
                Menu Add String, gv.hPopM , "Move Right", %ITV_MVRIGHT, %mf_enabled
                Menu Add String, gv.hPopM , "Help with Drag-Drop", %ITV_MVHELP, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "Sort SubTree", %ITV_SRTSUB, %mf_enabled
                Menu Add String, gv.hPopM , "Sort Total Tree", %ITV_SRTTREE, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "Collapse SubTree", %ITV_COLSUB, %mf_enabled
                Menu Add String, gv.hPopM , "Collapse Total Tree", %ITV_COLTREE, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "Expand SubTree", %ITV_EXPSUB, %mf_enabled
                Menu Add String, gv.hPopM , "Expand Total Tree", %ITV_EXPTREE, %mf_enabled
                AppendMenu(gv.hPopM, %MF_SEPARATOR, 0, $Nul)
                Menu Add String, gv.hPopM , "SubTree Statistics", %ITV_SUBSTATS, %mf_enabled
    
                Menu Attach gv.hPopM, gv.hTree    ' gv.hTree    'Cb.Hndl
    
    
            Case %WM_CONTEXTMENU
    '            TrackPopup gv.hTree, gv.hPopM, %TPM_LEFTALIGN   ' need it on TreeVew only, not all over dialog
    
            Case %wm_size
                ' Resize the toolbar as the dialog is resized
    
            Case %WM_DROPFILES
                ' Drag+Drop file handler
                Local lFileCnt As Long
                Local szFile   As Asciiz * %MAX_PATH
                lFileCnt = DragQueryFile(Cb.WParam, -1, ByVal 0, 0)
                For i = 0 To lFileCnt - 1
                    DragQueryFile Cb.WParam, i, szFile, SizeOf(szFile)
                    MsgBox Format$(i + 1) + " of " + Format$(lFileCnt) + $Cr + _
                        szFile, %mb_taskmodal
                Next i
                DragFinish CbWParam
    
            Case %wm_destroy
                ' Clean up before dialog is destroyed
                DragAcceptFiles Cb.Hndl, %FALSE
    
            Case %wm_ncactivate
                Static hWndSaveFocus As Dword
                If IsFalse Cb.WParam Then
                    ' Save control focus
                    hWndSaveFocus = GetFocus()
                ElseIf hWndSaveFocus Then
                    ' Restore control focus
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                End If
    
            Case %wm_command
                ' Process control notifications
                Select Case As Long Cb.Ctl
    
                    ' TreeView Menu Items
                    Case %ITV_INSCHILD       ' Insert Child Node
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Insert Child Clicked"
                        End If
    
                    Case %ITV_INSBEFORE      ' Insert Node Before
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Insert Node Before Clicked"
                        End If
    
                    Case %ITV_INSAFTER       ' Insert Node After
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Insert Node After  Clicked"
                        End If
    
                    Case %ITV_EDNODE         ' Edit Selected Node
                        If Cb.CtlMsg = %bn_clicked Then
                            gv.hNode  = TreeView_GetSelection(gv.hTree)
                            If gv.hNode  Then MsgBox "Handle ok"
                            SetFocus gv.hTree
                            htvedit&  = (SendMessage (gv.hTree, %TVM_EDITLABEL, 0, gv.hNode))
                            If htvedit& Then
                                Treeview Get Text gv.hDlg, %IDC_TREEVIEW, gv.hNode To txt$
                                MsgBox " Edit Selected Node Clicked "   + txt$
                            End If
                        End If
    
                    Case %ITV_DELNODE        ' Delete Selected  Node
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Edit Selected Node Clicked "   + txt$
                        End If
    
                    Case %ITV_UNDO           ' Undo last action
                        If Cb.CtlMsg = %bn_clicked Then
                            SendMessage gv.hTree, %EM_UNDO, 0, 0
                        End If
    
                    Case %ITV_MVUP           ' Move Up
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Move Up Clicked"
                        End If
    
                    Case %ITV_MVDOWN         ' Move Down
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Move Down Clicked"
                        End If
    
                    Case %ITV_MVLEFT         ' Move Left
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Move Left Clicked"
                        End If
    
                    Case %ITV_MVRIGHT        ' Move Right
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Move Right Clicked"
                        End If
    
                    Case %ITV_MVHELP         ' Help with Drag-Drop
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Help with Drag-Drop Clicked"
                        End If
    
                    Case %ITV_SRTSUB         ' Sort SubTree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Sort SubTree Clicked"
                        End If
    
                    Case %ITV_SRTTREE        ' Sort Total Tree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Sort Total Tree Clicked"
                        End If
    
                    Case %ITV_COLSUB         ' Collapse SubTree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Collapse SubTree Clicked"
                        End If
    
                    Case %ITV_COLTREE        ' Collapse Total Tree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Collapse Total Tree Clicked"
                        End If
    
                    Case %ITV_EXPSUB         ' Expand SubTree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Expand SubTree Clicked"
                        End If
    
                    Case %ITV_EXPTREE        ' Expand Total Tree
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " Expand Total Tree  Clicked"
                        End If
    
                    Case %ITV_SUBSTATS       ' SubTree Statistics
                        If Cb.CtlMsg = %bn_clicked Then
                            MsgBox " SubTree Statistics Clicked"
                        End If
    
                    Case %idcancel               ' Exit on Esc
                        Dialog Post Cb.Hndl, %wm_user+999&, 0, 0    ' Message to common Close-program routine
    
                End Select   ' Cb.Ctl
    
    
            Case %wm_notify
                pNMHDR = Cb.LParam
    
                Select Case @pNMHDR.idFrom
    
                    Case %IDC_TREEVIEW
                    Select Case @pNMHDR.code
                        Case %nm_rclick
                            SetFocus gv.hTree
                            TrackPopup Cb.Hndl, gv.hPopM, %TPM_LEFTALIGN
                            Exit Function
                        Case %tvn_beginlabeledit
                            MsgBox "Begin Edit"
                            'get treeview edit control handle
                            htvedit& = Treeview_GetEditControl(gv.hTree)
                            If htvedit& Then MsgBox "Successfull"
    
                            'set max text limit
                            Control Send gv.hTree, getdlgctrlid(htvedit&), %em_limittext, %maxlabellength, 0
    
                            'begin subclassing the edit control
                            gv.tEdsbcls = setwindowlong(htvedit&, %gwl_wndproc, ByVal CodePtr(treevieweditproc))
                            SetFocus htvedit&
    
                        Case %tvn_endlabeledit
                            MsgBox "End Edit"
                            'end subclassing the edit control
                            htvedit& = Treeview_GetEditControl(gv.hTree)
                            If htvedit& Then MsgBox "Successfull again"
    
                            setwindowlong htvedit&, %gwl_wndproc, gv.tEdsbcls
                            gv.tEdsbcls = 0
    
                            'update richedit control with new text
                            ptvdi = CbLParam
                            If @ptvdi.item.psztext Then
                                MsgBox "before call"
                                Call sendmessage(gv.hTree, %wm_settext, 0, @ptvdi.item.psztext)
                                ' tell windows to save the new text
                                Function = %true
                            Else
                                Function = %false
                            End If
    
    
                    End Select ' @pNMHDR.code
    
                End Select   ' @pNMHDR.idFrom
    
    
            Case %wm_syscommand
                 If Cb.WParam = %sc_close Then            ' "X" in top right corner is pressed or closed from
                     Dialog Post Cb.Hndl, %wm_user+999&, 0, 0    ' Message to common Close-program routine
                     Function = 1
                     Exit Function                  ' Closing/Ending is handled in  wm_user+999&
                 End If
    
           Case %wm_user + 999&       ' common Close handling routine (all close, exit or quit MUST be directed here
                 Dialog End Cb.Hndl
    
        End Select   ' Cb.Msg
    End Function
    '------------------------------------------------------------------------------
    '------------------------------------------------------------------------------
    '   ** Sample Code **
    '------------------------------------------------------------------------------
    Function SampleTreeViewInsertItem(ByVal hTree As Dword, ByVal hParent As _
                                        Dword, sItem As String) As Long
    
        Local tTVItem   As TV_ITEM
        Local tTVInsert As TV_INSERTSTRUCT
    
        If hParent Then
            tTVItem.mask      = %TVIF_CHILDREN Or %TVIF_HANDLE
            tTVItem.hItem     = hParent
            tTVItem.cchildren = 1
            TreeView_SetItem(hTree, tTVItem)
        End If
    
        tTVInsert.hParent              = hParent
        tTVInsert.Item.Item.mask       = %TVIF_TEXT
        tTVInsert.Item.Item.pszText    = StrPtr(sItem)
        tTVInsert.Item.Item.cchTextMax = Len(sItem)
    
        Function = TreeView_InsertItem(hTree, tTVInsert)
    End Function
    '------------------------------------------------------------------------------
    ' SampleTreeView
    '------------------------------------------------------------------------------
    Function SampleTreeView(ByVal hDlg As Dword, ByVal lID As Long, _
                            ByVal lCount As Long) As Long
        Local i       As Long
        Local j       As Long
        Local k       As Long
        Local hCtl    As Dword
        Local hRoot   As Dword
        Local hParent As Dword
    
        Control Handle hDlg, lID To hCtl
    
        For i = 1 To lCount
            hRoot = SampleTreeViewInsertItem(hCtl, %NULL, Using$("Root#", i))
            For j = 1 To lCount
                hParent = SampleTreeViewInsertItem(hCtl, hRoot, Using$("Item#", j))
                For k = 1 To lCount
                    Call SampleTreeViewInsertItem(hCtl, hParent, _
                        Using$("SubItem#_.#", j, k))
                Next k
            Next j
        Next i
    End Function
    '------------------------------------------------------------------------------
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Track Popup Menu
    '------------------------------------------------------------------------------
    Function TrackPopup( ByVal hDlg As Long, ByVal hSubMenu As Long, ByVal nFlags As Long ) As Long
    
        Dim hWnd    As Long
        Dim Result  As Long
        Dim PA      As POINTAPI
    
        '// We align the menu near the mouse.
        GetCursorPos PA
    
        If hWnd = 0 Then hWnd = WindowFromPoint( PA.X, PA.Y )
    
        '// Send a WM_INITMENU, unf. this messages seem to occur twice while sending it only once...(??)
        If hDlg Then SendMessage hDlg, %WM_INITMENU, hSubMenu, ByVal 0&
    
        Result = TrackPopupMenuEx( hSubMenu, %TPM_RETURNCMD Or %TPM_NONOTIFY Or nFlags, PA.X, PA.Y, hWnd, ByVal 0& )
    '    Result = TrackPopupMenuEx( hSubMenu, nFlags, PA.X, PA.Y, hWnd, ByVal 0& )
    
        '// Re-send message using the WM_COMMAND message.
        If Result <> 0 And hDlg <> 0 Then SendMessage hDlg, %wm_command, MakLng( Result, 0 ), ByVal 0&
    
        Function = Result
    
    End Function
    '------------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------
    ' Edit Procedure
    '------------------------------------------------------------------------------
    Function treevieweditproc(ByVal hctl As Long, ByVal msg As Long, _
                              ByVal wparam As Long, ByVal lparam As Long) Export As Long
    
        Static lcharcount As Long
    
        Select Case As Long msg
          Case %wm_getdlgcode
            Function = %dlgc_wantallkeys
            Exit Function
        End Select
    
        Function = callwindowproc( ByVal gv.tEdsbcls, hctl, msg, wparam, lparam)
    
    End Function
    '------------------------------------------------------------------------------
    Andre Jacobs
    "The problem with Computers is that they do what you tell them, not what you want them to"

  • #2
    Just for what im seeing here (and before testing cuz im in a hurry), i see lots
    of MSGBOX's in there.

    When a Messagebox is created, it causes other dialogs and controls to lose focus.
    When the label of a treeview loses focus, the edition is automatically cancelled,
    closing edition.

    Try removing all MSGBOXes from the code and run the code again and see
    if it makes any diference.

    Comment


    • #3
      There's lots of other things like this here, but this is a good (?) way to display debugging lines like the above from pb/Windows:

      Simple STDOUT for PB/DLL and PB/Win 2-13-04

      Usage:
      Code:
      #INCLUDE "STDOUT_PBWIN.INC" 
      
      
          ...
            STDOUT "GOT MESSAGE WM-XXXX" 
            .....
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Thanks Elias, It was the MsgBox after the TVM_EDITLABEL, which I included to see if it worked.

        Michael, the STDOUT to a file is very, very nice.
        If it is used with a console, then the editcontrol still lose the function and the edit does not complete, the same happens when I shell to the notepad file.
        I just converted it to append to the file, now I can follow the code, without having to "OK" those pesky MSGBOX's enerytime.
        The file needs to be manually cleared though - that is not much of a problem
        When I don't need it anymore, the include gets removed and the compiler will tell me if I've left any "STDOUT" calls (not like the MSGBOX's that can be left behind, once the testing/checking/debugging is done)


        STDOUT.INC
        Code:
        #If %def(%pb_win32)
        '-------------------------------------------------------------------------------------------
         Declare Function StdOut (Z As String) As Long
         Declare Function WriteStdOut (Z As String) As Long
        '-------------------------------------------------------------------------------------------
        
        '-------------------------------------------------------------------------------------------
         Function WriteStdOut (Z As String) As Long
          ' returns TRUE (non-zero) on success
        
            Local hStdOut As Long, nCharsWritten As Long
            Local w As String
        
        
            hStdOut      = GetStdHandle (%STD_OUTPUT_HANDLE)
            If hSTdOut   = -1&  Or hStdOut = 0&  Then     ' invalid handle value, coded in line to avoid
                                                         ' casting differences in Win32API.INC
                                                         ' %NULL test added for Win/XP
             AllocConsole
             hStdOut  = GetStdHandle (%STD_OUTPUT_HANDLE)
            End If
            w = Z & $CrLf
            Function = WriteFile(hStdOut, ByVal StrPtr(W), Len(W),  nCharsWritten, ByVal %NULL)
        
        
         End Function
        '-------------------------------------------------------------------------------------------
        
        '-------------------------------------------------------------------------------------------
         Function StdOut (Z As String) As Long
         '    Local x As Long
        
         '    'First, try with a console
         '    For x = 1 To 10
         '        WriteStdOut "This is line #" & Str$(x) & " of STDOUT to console"
         '    Next
        
             ' now redirect the output to a disk file...
             Local hFile As Long, hSys As Long, szFile As Asciiz * %MAX_PATH
             szFile  = "My_pbwin_stdout.txt"
             hFile   = FreeFile
             Open      szFile For Append As hFile
             hSys    = FileAttr(hFile,2)             ' get system handle
             SetStdHandle %STD_OUTPUT_HANDLE, hSys   ' make this file the STDOUT for this process
        
             WriteStdOut "Date:- " & Date$ & " Time:- " & Time$
             WriteStdOut Z
             WriteStdOut "     "
         '   WriteStdOut "End of File"
             Close hFile    ' close the PB handle, which will close the system handle
        
             ' show the file to prove success..
         '    x = Shell("Notepad.exe " & szFile)
        
         End Function
        '-------------------------------------------------------------------------------------------
        
        #EndIf
        
        '-------------------------------------------------------------------------------------------
        One tiny problem I still need help with:

        When the menu is selected via a right button click, it might not necessary be on the "selected" item, how can I make it the selected item?
        The TreeView_SetItem macro and/or the TVM_SETITEM message need the handle for the item, which I do not have.
        Or maybe, how can I get the handle of the item on which it was right-clicked?
        Andre Jacobs
        "The problem with Computers is that they do what you tell them, not what you want them to"

        Comment


        • #5
          Or maybe, how can I get the handle of the item on which it was right-clicked?
          You are going to have to get that 'hitem' to do just about anything.

          You have to go the long way...
          Code:
          GetCursorPos 
          ScreenToClient
          TreeView_HitTest
          TreeView_SelectItem
          Or, write a "wrapper" function to do this....

          Code:
           
          FUNCTION TreeView_SelectNodeAtCursor (BYVAL hTV as LONG) AS LONG
          
          ...
          END FUNCTION
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Thanks Michael,

            It was the TreeView_HitTest that eluded me, it was only when I knew that this is the one to use (and the documentation read with more attention) that the documentation actually made sense.

            Also thanks for the ScreenToClient titbit, without that I would have floundered for some time.

            This is what I ended up doing:
            Code:
            '------------------------------------------------------------------------------
            ' Make Node at Curser the Selected one  (when right clicked)
            '------------------------------------------------------------------------------
            Function TreeView_SelectNodeAtCursor (ByVal hTV As Long) As Long
                Dim pa      As POINTAPI
                Dim cp      As TV_HITTESTINFO
            
                ' get the curser position and update the hittest structure
                GetCursorPos pa
                cp.pt = pa
            
                ' Convert screen coordinates to client coordinates
                ScreenToClient (hTV, cp.pt)
            
                ' Find Closest Item/Node in the TreeView
                TreeView_HitTest (hTV, cp)
            
                ' set/select the Item/Node (only if the curser is close to an Item)
                If cp.hItem Then
                    TreeView_SelectItem (hTV, cp.hItem)
                End If
            
            
            End Function
            '--------------------------------------------------------------------------
            Andre Jacobs
            "The problem with Computers is that they do what you tell them, not what you want them to"

            Comment


            • #7
              >ScreenToClient titbit, without that I would have floundered for some time

              Tell me about it. I sure did the first time.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment

              Working...
              X