A lot of TreeView Stuff :-)

Share your advanced PureBasic knowledge/code with the community.
Andy
User
User
Posts: 18
Joined: Wed Jun 18, 2003 8:32 pm
Location: Switzerland

TreeGadget individual sort

Post by Andy »

Great stuff to find here, well. But I need another functionality for sorting the items in the TreeGadget (descending instead of ascending). The only possibility to sort individual is the TVM_SORTCHILDRENCB message, which I have found by MS. But I have problems with that...

Code: Select all

Procedure.l _CompareFunc(lParam1.l, lParam2.l, lParamSort.l) 
  ;only for testing - I give out the parameters 
  Debug "------------------" 
  Debug lParam1 ;should not be zero...
  Debug lParam2 ;should not be zero...
  Debug lParamSort ;my own parameter - this one works...
  ProcedureReturn 1 ;only for testing - give something back - this works too
EndProcedure 

Structure TVSORTCB 
  hParent.l 
  lpfnCompare.l 
  lParam.l 
EndStructure 

DefType.TVSORTCB psort 

If OpenWindow(0, 264, 183, 491, 377,  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "SortTree")=0 
  End 
EndIf 

If CreateGadgetList(WindowID())=0 
  End 
EndIf 

TreeGadget(1, 10, 70, 470, 300) 
VHndl=AddGadgetItem (1, -1, "Root") 
OpenTreeGadgetNode(1) 
AddGadgetItem (1, -1, "Zenia") 
AddGadgetItem (1, -1, "Michael") 
AddGadgetItem (1, -1, "Andy") 
AddGadgetItem (1, -1, "Chris") 
CloseTreeGadgetNode(1) 
ButtonGadget(2, 10, 10, 40, 20, "Sort") 
While EventGadgetID()<>2 ;very easy event trapping - only for testing
  WaitWindowEvent() 
Wend 

psort\hParent=VHndl 
psort\lpfnCompare=@_CompareFunc() 
psort\lParam=5 ;my own parameter
;SendMessage_(GadgetID(1),#TVM_SORTCHILDREN,#False,VHndl)
;the message above works (like described by freak)
SendMessage_(GadgetID(1),#TVM_SORTCHILDRENCB,0,@psort) 

While WindowEvent()<>#PB_Event_CloseWindow:Delay(1):Wend 

End 
lParam1 and lParam2 are always zero - so I do something wrong there. But I can not find a solution - I have try it... Could anybody help me? Thank you.

Best Regards
Andy
halo
Enthusiast
Enthusiast
Posts: 104
Joined: Mon Jan 26, 2004 2:49 am

Post by halo »

Here's how to set a node's icon!

Structure TVITEM
mask.l
hItem.l
state.l
stateMask.l
pszText.l
cchTextMax.l
iImage.l
iSelectedImage.l
cChildren.l
lParam.l
EndStructure

InitCommonControls_()

ProcedureDLL.l CreateImageList()
ProcedureReturn ImageList_Create_(16,16,#ILC_COLOR16,2,4)
EndProcedure

ProcedureDLL ImageListAdd(hndImgList,hndimage)
ImageList_Add_(hndImgList,hndimage,0)
EndProcedure

ProcedureDLL SetTreeViewNodeIcon(treeviewnode)
hitem=PeekL(treeviewnode+28)
hwnd=PeekL(treeviewnode+24)
TVITEM.TVITEM
TVITEM\hItem=hitem
SendMessage_(hwnd,#TVM_GETITEM,0,TVITEM.TVITEM)
TVITEM\mask=#TVIF_IMAGE+#TVIF_SELECTEDIMAGE
TVITEM\iImage=1
TVITEM\iSelectedImage=1
SendMessage_(hwnd,#TVM_SETITEM,0,TVITEM.TVITEM)
EndProcedure
Post Reply