Announcement

Collapse
No announcement yet.

Have I found a bug in PB 9.0?

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

  • Have I found a bug in PB 9.0?

    To All:

    While trying to turn the BOLD attribute ON/OFF for a treeview item it seems I can only turn the attribute ON. The following program, originally by Kev Peel and slightly modified by me illustrates the problem.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    '________________________________________________________________________________________
    '
    ' TreeView search function test
    '
    ' A small demonstration of finding some text in a treeview.
    ' Item handle is displayed if the text is found.
    '
    '________________________________________________________________________________________
    
    %USEMACROS = 1
    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"
    
    %IDC_TEXT           = 100       ' Search text
    %IDC_TREE           = 200       ' Tree with items
    
    
    '------------------------------------------------------------------------------
    ' Return the treeview item handle that resembles a given string.
    '
    '       hTreeview is the treeview list to search
    '       sQuery is the string to search for
    '       nCaseSens is nonzero for a case sensitive search, else case insenstive.
    '       hStartItem is the parent tree branch to start from (use 0 for root)
    '       nSearchChildren is nonzero to search subitems
    '       nSelectItem is nonzero to select the string found
    '       hItem is the item to search from (optional)
    '
    ' Returns the item if successful. Or 0 if it cannot find the string.
    '------------------------------------------------------------------------------
    FUNCTION TreeView_FindItem(BYVAL hTreeView AS DWORD, _
                               BYVAL sQuery AS STRING, _
                               BYVAL nCaseSens AS LONG, _
                               BYVAL hStartItem AS DWORD, _
                               BYVAL nSearchChildren AS LONG, _
                               BYVAL nSelectItem AS LONG, _
                               OPTIONAL BYVAL hItem AS DWORD) AS DWORD
    
      LOCAL tvi   AS TV_ITEM
      LOCAL zText AS ASCIIZ * 1024
      LOCAL hTmp  AS DWORD
    
      tvi.mask       = %TVIF_TEXT OR %TVIF_CHILDREN
      tvi.pszText    = VARPTR(zText)
      tvi.cchTextMax = SIZEOF(zText)
    
        IF nCaseSens = %False THEN sQuery = UCASE$(sQuery)
    
      ' Loop through items starting from hStartItem...
      tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, IIF&(hItem, %TVGN_NEXT, %TVGN_CHILD), IIF&(hItem, hItem, hStartItem))
    
      DO UNTIL (tvi.hItem = %NULL)
        SendMessage hTreeView, %TVM_GETITEM, 0, VARPTR(tvi)
          IF nCaseSens = %False THEN
            IF UCASE$(zText) = sQuery THEN EXIT DO
          ELSE
            IF zText = sQuery THEN EXIT DO
          END IF
    
          ' Search child items (we use this function again in a loop)...
          IF (nSearchChildren <> 0) AND (tvi.cChildren <> 0) THEN
            hTmp = TreeView_FindItem(hTreeView, sQuery, nCaseSens, tvi.hItem, %True, nSelectItem, %Null)
              IF hTmp <> %Null THEN
                'Item was found so exit now...
                FUNCTION = hTmp
                EXIT FUNCTION
              END IF
         END IF
    
        tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, %TVGN_NEXT, tvi.hItem)
      LOOP
    
        IF (tvi.hItem <> %NULL) AND (nSelectItem <> %False) THEN
          'Select the string if required...
          SendMessage(hTreeView, %TVM_SELECTITEM, %TVGN_CARET, tvi.hItem)
        END IF
    
      ' Return item and exit...
      FUNCTION = tvi.hItem
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    ' Main dialog procedure
    '------------------------------------------------------------------------------
    CALLBACK FUNCTION dlgMain
    
      LOCAL sText AS STRING
      STATIC hItem AS DWORD
    
      SELECT CASE CB.MSG
        CASE %WM_COMMAND
            IF (CB.CTL = %IDOK) AND (CB.CTLMSG = %BN_CLICKED) THEN
              CONTROL GET TEXT CB.HNDL, %IDC_TEXT TO sText
                IF LEN(sText) THEN
                  ' Look for search text in the treeview...
                  hItem = TreeView_FindItem(GetDlgItem(CB.HNDL, %IDC_TREE), sText, %False, %Null, %True, %True, hItem)
    
    '              MessageBox CBHNDL, IIF$(hItem, "Text found, item index was:" + STR$(hItem), _
    '              "Text not found. It might already be selected."), "TreeView Search Test", %MB_ICONINFORMATION
    
                  CONTROL SET FOCUS CB.HNDL, %IDC_TREE
    
                  '------------------------------------------------------------
                  'A POSSIBLE BUG IN PB 9.0
                  '
                  'The following 3 statements should display the TreeView item in
                  'BOLD type face, wait for 1 second, then display the same
                  'treeview item in normal type face, BUT IT DOESN'T WORK!!!
                  'THE FOLLOWING STATEMENT TURNS ON THE BOLD TYPEFACE FOR THIS ITEM.
                  TREEVIEW SET BOLD CB.HNDL, %IDC_TREE, hItem, -1
                  SLEEP 1000
    
                  'THE FOLLOWING STATEMENT IS SUPPOSED TO TURN *OFF* BOLD TYPEFACE
                  'FOR THE CURRENT ITEM, BUT DOES NOT APPEAR TO WORK AS ADVERTISED
                  'AND DOCUMENTED.
                  '
                  'AN EXPERIMENT...
                  'Comment out the above two lines, then run this program again.
                  'THE FOLLOWING STATEMENT APPEARS TO TURN *ON* BOLD TYPEFACE,
                  'EVEN THOUGH THE FLAG IS SET TO TURN BOLD *OFF*!!!
                  TREEVIEW SET BOLD CB.HNDL, %IDC_TREE, hItem, 0
    
                  FUNCTION = 1
                END IF
            END IF
      END SELECT
    
    END FUNCTION
    
    '------------------------------------------------------------------------------
    ' Program Start Point
    '------------------------------------------------------------------------------
    FUNCTION PBMAIN
    
      LOCAL hDlg  AS DWORD
      LOCAL tvis  AS TV_INSERTSTRUCT
      LOCAL zText AS ASCIIZ * 128
      LOCAL i     AS LONG
    
      InitCommonControls
    
      'Create user interface with sample treeview...
      DIALOG NEW 0, "TreeView Search Test", , , 225, 150, %DS_MODALFRAME OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
    
      CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT, "Red", 7, 7, 180, 12
      CONTROL ADD BUTTON, hDlg, %IDOK, "Find", 190, 7, 25, 12, %BS_DEFAULT OR %WS_TABSTOP
      CONTROL ADD $WC_TREEVIEW, hDlg, %IDC_TREE, "", 7, 22, 208, 120, %WS_CHILD OR %WS_TABSTOP OR _
      %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, %WS_EX_CLIENTEDGE
    
      tvis.hInsertAfter = %TVI_LAST
      tvis.item.item.mask = %TVIF_TEXT OR %TVIF_CHILDREN
      tvis.item.item.pszText = VARPTR(zText)
      tvis.item.item.cChildren = %True
      zText = "Colors"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis) TO tvis.hParent
    
      'Place some sample items...
      tvis.item.item.cChildren = %False
      zText = "Red"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      zText = "Green"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      zText = "Blue"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      zText = "Yellow"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      zText = "Black"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      zText = "White"
      CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
    
      'Include extra items for find/next search...
      FOR i = 1 TO 100
        zText = "Item" + FORMAT$(i,"000")
        CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
      NEXT i
    
      DIALOG SHOW MODAL hDlg CALL dlgMain
    
    END FUNCTION
    The problems appears to be in "CALLBACK FUNCTION dlgMain" and is commented as to the effects the "TREEVIEW SET BOLD" DDT statement performs. It appears once you have turned ON the BOLD attribute for the selected item you cannot turn it OFF.
    Later...

    JR

    "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

  • #2
    The DDT Treeview statements are only valid if you have a CONTROL ADD TREEVIEW and not a CONTROL ADD "custom control".
    Sincerely,

    Steve Rossell
    PowerBASIC Staff

    Comment


    • #3
      Steve,

      The DDT Treeview statements are only valid if you have a CONTROL ADD TREEVIEW and not a CONTROL ADD "custom control".
      This restriction is not mentioned in the documentation.

      Besides that, if what you say is true, then the "TREEVIEW SET BOLD" statement should not have turned ON the BOLD attribute either. So IMO this is a bug.
      Later...

      JR

      "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

      Comment


      • #4
        To All:

        OK, round 2.

        Recoded the app to use "CONTROL ADD TREEVIEW" DDT statement. No change in the result, the treeview item attribute is set to BOLD, even with specifying the BOLD attribute turned OFF.

        Code:
        #COMPILE EXE
        #DIM ALL
        
        '________________________________________________________________________________________
        '
        ' TreeView search function test
        '
        ' A small demonstration of finding some text in a treeview.
        ' Item handle is displayed if the text is found.
        '
        '________________________________________________________________________________________
        
        %USEMACROS = 1
        #INCLUDE "win32api.inc"
        #INCLUDE "commctrl.inc"
        
        %IDC_TEXT           = 100       ' Search text
        %IDC_TREE           = 200       ' Tree with items
        
        
        '------------------------------------------------------------------------------
        ' Return the treeview item handle that resembles a given string.
        '
        '       hTreeview is the treeview list to search
        '       sQuery is the string to search for
        '       nCaseSens is nonzero for a case sensitive search, else case insenstive.
        '       hStartItem is the parent tree branch to start from (use 0 for root)
        '       nSearchChildren is nonzero to search subitems
        '       nSelectItem is nonzero to select the string found
        '       hItem is the item to search from (optional)
        '
        ' Returns the item if successful. Or 0 if it cannot find the string.
        '------------------------------------------------------------------------------
        FUNCTION TreeView_FindItem(BYVAL hTreeView AS DWORD, _
                                   BYVAL sQuery AS STRING, _
                                   BYVAL nCaseSens AS LONG, _
                                   BYVAL hStartItem AS DWORD, _
                                   BYVAL nSearchChildren AS LONG, _
                                   BYVAL nSelectItem AS LONG, _
                                   OPTIONAL BYVAL hItem AS DWORD) AS DWORD
        
          LOCAL tvi   AS TV_ITEM
          LOCAL zText AS ASCIIZ * 1024
          LOCAL hTmp  AS DWORD
        
          tvi.mask       = %TVIF_TEXT OR %TVIF_CHILDREN
          tvi.pszText    = VARPTR(zText)
          tvi.cchTextMax = SIZEOF(zText)
        
            IF nCaseSens = %False THEN sQuery = UCASE$(sQuery)
        
          ' Loop through items starting from hStartItem...
          tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, IIF&(hItem, %TVGN_NEXT, %TVGN_CHILD), IIF&(hItem, hItem, hStartItem))
        
          DO UNTIL (tvi.hItem = %NULL)
            SendMessage hTreeView, %TVM_GETITEM, 0, VARPTR(tvi)
              IF nCaseSens = %False THEN
                IF UCASE$(zText) = sQuery THEN EXIT DO
              ELSE
                IF zText = sQuery THEN EXIT DO
              END IF
        
              ' Search child items (we use this function again in a loop)...
              IF (nSearchChildren <> 0) AND (tvi.cChildren <> 0) THEN
                hTmp = TreeView_FindItem(hTreeView, sQuery, nCaseSens, tvi.hItem, %True, nSelectItem, %Null)
                  IF hTmp <> %Null THEN
                    'Item was found so exit now...
                    FUNCTION = hTmp
                    EXIT FUNCTION
                  END IF
             END IF
        
            tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, %TVGN_NEXT, tvi.hItem)
          LOOP
        
            IF (tvi.hItem <> %NULL) AND (nSelectItem <> %False) THEN
              'Select the string if required...
              SendMessage(hTreeView, %TVM_SELECTITEM, %TVGN_CARET, tvi.hItem)
            END IF
        
          ' Return item and exit...
          FUNCTION = tvi.hItem
        
        END FUNCTION
        
        '------------------------------------------------------------------------------
        ' Main dialog procedure
        '------------------------------------------------------------------------------
        CALLBACK FUNCTION dlgMain
        
          LOCAL sText AS STRING
          STATIC hItem AS DWORD
        
          SELECT CASE CB.MSG
            CASE %WM_COMMAND
                IF (CB.CTL = %IDOK) AND (CB.CTLMSG = %BN_CLICKED) THEN
                  CONTROL GET TEXT CB.HNDL, %IDC_TEXT TO sText
                    IF LEN(sText) THEN
                      ' Look for search text in the treeview...
                      hItem = TreeView_FindItem(GetDlgItem(CB.HNDL, %IDC_TREE), sText, %False, %Null, %True, %True, hItem)
        
        '              MessageBox CBHNDL, IIF$(hItem, "Text found, item index was:" + STR$(hItem), _
        '              "Text not found. It might already be selected."), "TreeView Search Test", %MB_ICONINFORMATION
        
                      CONTROL SET FOCUS CB.HNDL, %IDC_TREE
        
                      '------------------------------------------------------------
                      'A POSSIBLE BUG IN PB 9.0
                      '
                      'The following 3 statements should display the TreeView item in
                      'BOLD type face, wait for 1 second, then display the same
                      'treeview item in normal type face, BUT IT DOESN'T WORK!!!
                      'THE FOLLOWING STATEMENT TURNS ON THE BOLD TYPEFACE FOR THIS ITEM.
                      TREEVIEW SET BOLD CB.HNDL, %IDC_TREE, hItem, -1
                      SLEEP 1000
        
                      'THE FOLLOWING STATEMENT IS SUPPOSED TO TURN *OFF* BOLD TYPEFACE
                      'FOR THE CURRENT ITEM, BUT DOES NOT APPEAR TO WORK AS ADVERTISED
                      'AND DOCUMENTED.
                      '
                      'AN EXPERIMENT...
                      'Comment out the above two lines, then run this program again.
                      'THE FOLLOWING STATEMENT APPEARS TO TURN *ON* BOLD TYPEFACE,
                      'EVEN THOUGH THE FLAG IS SET TO TURN BOLD *OFF*!!!
                      TREEVIEW SET BOLD CB.HNDL, %IDC_TREE, hItem, 0
                      
                    END IF
                END IF
          END SELECT
        
        END FUNCTION
        
        '------------------------------------------------------------------------------
        ' Program Start Point
        '------------------------------------------------------------------------------
        FUNCTION PBMAIN
        
          LOCAL hDlg   AS DWORD
          LOCAL hRoot  AS DWORD
          LOCAL hChild AS DWORD
        
          LOCAL tvis  AS TV_INSERTSTRUCT
          LOCAL zText AS ASCIIZ * 128
          LOCAL i     AS LONG
        
          InitCommonControls
        
          'Create user interface with sample treeview...
          DIALOG NEW 0, "TreeView Search Test", , , 225, 150, %DS_MODALFRAME OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
        
          CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT, "Red", 7, 7, 180, 12
          CONTROL ADD BUTTON, hDlg, %IDOK, "Find", 190, 7, 25, 12, %BS_DEFAULT OR %WS_TABSTOP
        
          CONTROL ADD TREEVIEW, hDlg, %IDC_TREE, "", 7, 22, 208, 120, _
            %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR _
            %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, _
            %WS_EX_CLIENTEDGE
        
        '  CONTROL ADD $WC_TREEVIEW, hDlg, %IDC_TREE, "", 7, 22, 208, 120, %WS_CHILD OR %WS_TABSTOP OR _
        '  %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, %WS_EX_CLIENTEDGE
        
          TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, 0, %TVI_FIRST, 0, 0, "Colors" TO hRoot
        
        '  tvis.hInsertAfter = %TVI_LAST
        '  tvis.item.item.mask = %TVIF_TEXT OR %TVIF_CHILDREN
        '  tvis.item.item.pszText = VARPTR(zText)
        '  tvis.item.item.cChildren = %True
        '  zText = "Colors"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis) TO tvis.hParent
        
          'Place some sample items...
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "Red" TO hChild
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "Green" TO hChild
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "Blue" TO hChild
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "Yellow" TO hChild
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "Black" TO hChild
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, "While" TO hChild
        
        '  tvis.item.item.cChildren = %False
        '  zText = "Red"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        '  zText = "Green"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        '  zText = "Blue"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        '  zText = "Yellow"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        '  zText = "Black"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        '  zText = "White"
        '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
        
          'Include extra items for find/next search...
          FOR i = 1 TO 100
            zText = "Item" + FORMAT$(i,"000")
            TREEVIEW INSERT ITEM  hDlg, %IDC_TREE, hRoot, %TVI_LAST, 0, 0, zText TO hChild
        '    CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
          NEXT i
        
          DIALOG SHOW MODAL hDlg CALL dlgMain
        
        END FUNCTION
        The plot thickens.
        Later...

        JR

        "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

        Comment


        • #5
          Don't let it drive you buggy!

          Just send in a report, and hope to find a work around. With so many new items this time around I really think we should expect a few little quirks that we have to put up with until they get the i's dotted and t's crossed.
          Rod
          I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

          Comment


          • #6
            Rod,

            No I won't let it get to me.

            When things like this happen when I program it usually means I've done something wrong. But I really can't see my mistake in this case. I just wanted someone else to take a look at this test app and see if they can't spot my error and/or duplicate my results before I send in a bug report.
            Later...

            JR

            "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

            Comment


            • #7
              Verification?

              As a quick verification I've added Treeview Get Bold command to confirm values.

              In the code I set bBold to a random value (12345). This verifies that Get Bold returns the set value.

              Treeview Set Bold with 0 (false) does not actually set the value to 0.

              Looks like Treeview Set Bold always sets it to -1 [True] (ignores the passed parameter value and always uses -1)?

              Code:
              #Compile Exe
              #Dim All
              
              '________________________________________________________________________________________
              '
              ' TreeView search function test
              '
              ' A small demonstration of finding some text in a treeview.
              ' Item handle is displayed if the text is found.
              '
              '________________________________________________________________________________________
              
              %USEMACROS = 1
              #Include "win32api.inc"
              #Include "commctrl.inc"
              
              %IDC_TEXT           = 100       ' Search text
              %IDC_TREE           = 200       ' Tree with items
              
              
              '------------------------------------------------------------------------------
              ' Return the treeview item handle that resembles a given string.
              '
              '       hTreeview is the treeview list to search
              '       sQuery is the string to search for
              '       nCaseSens is nonzero for a case sensitive search, else case insenstive.
              '       hStartItem is the parent tree branch to start from (use 0 for root)
              '       nSearchChildren is nonzero to search subitems
              '       nSelectItem is nonzero to select the string found
              '       hItem is the item to search from (optional)
              '
              ' Returns the item if successful. Or 0 if it cannot find the string.
              '------------------------------------------------------------------------------
              Function TreeView_FindItem(ByVal hTreeView As Dword, _
                                         ByVal sQuery As String, _
                                         ByVal nCaseSens As Long, _
                                         ByVal hStartItem As Dword, _
                                         ByVal nSearchChildren As Long, _
                                         ByVal nSelectItem As Long, _
                                         Optional ByVal hItem As Dword) As Dword
              
                Local tvi   As TV_ITEM
                Local zText As Asciiz * 1024
                Local hTmp  As Dword
              
                tvi.mask       = %TVIF_TEXT Or %TVIF_CHILDREN
                tvi.pszText    = VarPtr(zText)
                tvi.cchTextMax = SizeOf(zText)
              
                  If nCaseSens = %False Then sQuery = UCase$(sQuery)
              
                ' Loop through items starting from hStartItem...
                tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, IIf&(hItem, %TVGN_NEXT, %TVGN_CHILD), IIf&(hItem, hItem, hStartItem))
              
                Do Until (tvi.hItem = %NULL)
                  SendMessage hTreeView, %TVM_GETITEM, 0, VarPtr(tvi)
                    If nCaseSens = %False Then
                      If UCase$(zText) = sQuery Then Exit Do
                    Else
                      If zText = sQuery Then Exit Do
                    End If
              
                    ' Search child items (we use this function again in a loop)...
                    If (nSearchChildren <> 0) And (tvi.cChildren <> 0) Then
                      hTmp = TreeView_FindItem(hTreeView, sQuery, nCaseSens, tvi.hItem, %True, nSelectItem, %Null)
                        If hTmp <> %Null Then
                          'Item was found so exit now...
                          Function = hTmp
                          Exit Function
                        End If
                   End If
              
                  tvi.hItem = SendMessage(hTreeView, %TVM_GETNEXTITEM, %TVGN_NEXT, tvi.hItem)
                Loop
              
                  If (tvi.hItem <> %NULL) And (nSelectItem <> %False) Then
                    'Select the string if required...
                    SendMessage(hTreeView, %TVM_SELECTITEM, %TVGN_CARET, tvi.hItem)
                  End If
              
                ' Return item and exit...
                Function = tvi.hItem
              
              End Function
              
              '------------------------------------------------------------------------------
              ' Main dialog procedure
              '------------------------------------------------------------------------------
              CallBack Function dlgMain
              
                Local sText As String
                Static hItem As Dword
              
                Select Case Cb.Msg
                  Case %wm_command
                      If (Cb.Ctl = %idok) And (Cb.CtlMsg = %bn_clicked) Then
                        Control Get Text Cb.Hndl, %IDC_TEXT To sText
                          If Len(sText) Then
                            ' Look for search text in the treeview...
                            hItem = TreeView_FindItem(GetDlgItem(Cb.Hndl, %IDC_TREE), sText, %False, %Null, %True, %True, hItem)
              
              '              MessageBox CBHNDL, IIF$(hItem, "Text found, item index was:" + STR$(hItem), _
              '              "Text not found. It might already be selected."), "TreeView Search Test", %MB_ICONINFORMATION
              
                            Control Set Focus Cb.Hndl, %IDC_TREE
              
                            '------------------------------------------------------------
                            'A POSSIBLE BUG IN PB 9.0
                            '
                            'The following 3 statements should display the TreeView item in
                            'BOLD type face, wait for 1 second, then display the same
                            'treeview item in normal type face, BUT IT DOESN'T WORK!!!
                            'THE FOLLOWING STATEMENT TURNS ON THE BOLD TYPEFACE FOR THIS ITEM.
                            Local bBold As Long
              
                            bBold = 12345
                            MsgBox Str$(bBold)
              
                            Treeview Get Bold Cb.Hndl, %IDC_TREE, hItem To bBold
              
                            MsgBox "Before value Bold= " + Str$(bBold)
                                            
                            Treeview Set Bold Cb.Hndl, %IDC_TREE, hItem, 0
              
                            bBold = 12345
                            Treeview Get Bold Cb.Hndl, %IDC_TREE, hItem To bBold
                            
                            MsgBox "After set -1 Bold= " + Str$(bBold)
                            'sleep 1000
              
                            'THE FOLLOWING STATEMENT IS SUPPOSED TO TURN *OFF* BOLD TYPEFACE
                            'FOR THE CURRENT ITEM, BUT DOES NOT APPEAR TO WORK AS ADVERTISED
                            'AND DOCUMENTED.
                            '
                            'AN EXPERIMENT...
                            'Comment out the above two lines, then run this program again.
                            'THE FOLLOWING STATEMENT APPEARS TO TURN *ON* BOLD TYPEFACE,
                            'EVEN THOUGH THE FLAG IS SET TO TURN BOLD *OFF*!!!
                            Control Set Focus Cb.Hndl, %IDC_TREE
                            
                            Treeview Set Bold Cb.Hndl, %IDC_TREE, hItem, 0
              
                            bBold = 12345 ' Set to random value
                            Treeview Get Bold Cb.Hndl, %IDC_TREE, hItem To bBold
                           
                            MsgBox "After Bold set off (0)= " + Str$(bBold) + $CrLf + "Looks like Treeview Set Bold does not set to 0" + $CrLf + "It does look like Treview Get Bold returns the correct value as initialized 12345, which was changed."
              
                              
              
                          End If
                      End If
                End Select
              
              End Function
              
              '------------------------------------------------------------------------------
              ' Program Start Point
              '------------------------------------------------------------------------------
              Function PBMain
              
                Local hDlg   As Dword
                Local hRoot  As Dword
                Local hChild As Dword
              
                Local tvis  As TV_INSERTSTRUCT
                Local zText As Asciiz * 128
                Local i     As Long
              
                InitCommonControls
              
                'Create user interface with sample treeview...
                Dialog New 0, "TreeView Search Test", , , 225, 150, %ds_modalframe Or %ws_caption Or %ws_sysmenu To hDlg
              
                Control Add TextBox, hDlg, %IDC_TEXT, "Red", 7, 7, 180, 12
                Control Add Button, hDlg, %idok, "Find", 190, 7, 25, 12, %bs_default Or %ws_tabstop
              
                Control Add Treeview, hDlg, %IDC_TREE, "", 7, 22, 208, 120, _
                  %ws_child Or %ws_tabstop Or %ws_visible Or %tvs_hasbuttons Or %tvs_haslines Or _
                  %tvs_linesatroot Or %tvs_showselalways, _
                  %ws_ex_clientedge
              
              '  CONTROL ADD $WC_TREEVIEW, hDlg, %IDC_TREE, "", 7, 22, 208, 120, %WS_CHILD OR %WS_TABSTOP OR _
              '  %WS_VISIBLE OR %TVS_HASBUTTONS OR %TVS_HASLINES OR %TVS_LINESATROOT OR %TVS_SHOWSELALWAYS, %WS_EX_CLIENTEDGE
              
                Treeview Insert Item  hDlg, %IDC_TREE, 0, %tvi_first, 0, 0, "Colors" To hRoot
              
              '  tvis.hInsertAfter = %TVI_LAST
              '  tvis.item.item.mask = %TVIF_TEXT OR %TVIF_CHILDREN
              '  tvis.item.item.pszText = VARPTR(zText)
              '  tvis.item.item.cChildren = %True
              '  zText = "Colors"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis) TO tvis.hParent
              
                'Place some sample items...
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "Red" To hChild
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "Green" To hChild
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "Blue" To hChild
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "Yellow" To hChild
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "Black" To hChild
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, "While" To hChild
              
              '  tvis.item.item.cChildren = %False
              '  zText = "Red"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              '  zText = "Green"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              '  zText = "Blue"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              '  zText = "Yellow"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              '  zText = "Black"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              '  zText = "White"
              '  CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
              
                'Include extra items for find/next search...
                For i = 1 To 100
                  zText = "Item" + Format$(i,"000")
                  Treeview Insert Item  hDlg, %IDC_TREE, hRoot, %tvi_last, 0, 0, zText To hChild
              '    CONTROL SEND hDlg, %IDC_TREE, %TVM_INSERTITEM, 0, VARPTR(tvis)
                Next i
              
                Dialog Show Modal hDlg Call dlgMain
              
              End Function

              Comment


              • #8
                Brian,

                Your tests confirm my results too. I'll send in a bug report as soon as I get my e-mail account straightened out with my new ISP.

                Thanks for taking a look.
                Later...

                JR

                "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

                Comment

                Working...
                X