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.
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.
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
Comment