Many thanks for your help, RASHAD. I've back-tracked a bit and removed the requirement to display the sub-directories, and I'll explain why. When including the sub-directories, if I click on a sub-directory of, say, the Music library, the text returned on the 'change' event type only returns that sub-directory name, not the full path name, and I obviously don't want to
display the full path name in every sub-directory entry in the tree.
By removing the display of any sub-directories from these extra entries I'm adding, I now treat these entries as shortcuts to the main tree. So in the code below, if the user clicks on the Music entry the 'change' event type will reset the tree to the actual 'Music' entry in the initial ExplorerTreeGadget list.
Here's the code, which provides the functionality I need:
Code: Select all
#TVGN_LASTVISIBLE = 10
Global tvi.TVITEM,lpis.TV_INSERTSTRUCT,buffer$
tvi\mask = #TVIF_TEXT
buffer$ = Space(#MAX_PATH)
tvi\pszText = @buffer$
tvi\cchTextMax = #MAX_PATH
Procedure AddItem(gadget.l, text.s)
hRoot = SendMessage_(GadgetID(gadget), #TVM_GETNEXTITEM, #TVGN_LASTVISIBLE, 0)
lpis\hParent = SendMessage_(GadgetID(gadget), #TVM_GETNEXTITEM, #TVGN_PARENT, hRoot)
lpis\hInsertAfter = hRoot
lpis\item\mask = #TVIF_TEXT
lpis\item\cchTextMax = Len(text)
lpis\item\pszText = @text
lpis\hParent = SendMessage_(GadgetID(gadget), #TVM_INSERTITEM, 0, @lpis)
EndProcedure
OpenWindow(0, 0, 0, 300, 350, "ExplorerTreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ExplorerTreeGadget(0, 10, 10, 280, 280, "*.*", #PB_Explorer_NoDriveRequester|#PB_Explorer_NoFiles)
SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #TVS_CHECKBOXES|#TVS_TRACKSELECT)
If OSVersion() >= #PB_OS_Windows_10
AddItem(0,"C:\Users\Public\Music")
AddItem(0,"C:\Users\Public\Pictures")
AddItem(0,"C:\Users\Public\Videos")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Change
DirName$ = GetGadgetText(0)
If FileSize(DirName$) = -1
tvi\hItem = SendMessage_(GadgetID(0), #TVM_GETNEXTITEM, #TVGN_CARET, 0)
SendMessage_(GadgetID(0), #TVM_GETITEM, 0, tvi)
DirName$ = Trim(buffer$) + "\"
SetGadgetText(0, DirName$)
EndIf
Debug DirName$
EndSelect
EndSelect
EndSelect
Until q = 1
Edit: Removed position and flag from AddItem as they are no longer needed