Treegadget problem...

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I know this is an oldie but I wanted to post this updated code for PB 4.3 and to correct some bugs.

Code: Select all

#CheckBoxYes = 0
#CheckboxNo = 1


Procedure WinCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_NOTIFY
      *nmhdr.NMHDR = lParam
      ;- Get the gadget #
      gad = GetDlgCtrlID_(*nmhdr\hwndFrom)
      ;- If the # matches our TreeGadget, proceed
      If *nmhdr\code = #NM_CUSTOMDRAW And gad = 1
        *tvcd.NMTVCUSTOMDRAW= lParam
        *tvcd\nmcd\lItemlParam
        item = *tvcd\nmcd\lItemlParam
        ;- See if the checkbox is set to on or off
        onoff = GetGadgetItemData(gad, item)
        ;- If it's set to off, prevent the checkbox from displaying
        If onoff
          tvi.TV_ITEM
          tvi\mask = #TVIF_HANDLE | #TVIF_STATE 
          tvi\hItem = GadgetItemID(gad, item) 
          tvi\state = 0
          tvi\stateMask = #TVIS_STATEIMAGEMASK 
          SendMessage_(*nmhdr\hwndFrom, #TVM_SETITEM, 0, tvi) 
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 400, 380, "Sparked TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TreeGadget(1, 180, 10, 160, 360, #PB_Tree_CheckBoxes) 
  SetWindowCallback(@WinCallback())
  For a = 0 To 1 
    AddGadgetItem (1, -1, "Normal Item "+Str(a), 0, 0) 
    AddGadgetItem (1, -1, "Node "+Str(a), 0, 0) 
    AddGadgetItem(1, -1, "Sub-Item 1", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 2", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 3", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 4", 0, 1) 
    AddGadgetItem (1, -1, "File "+Str(a), 0, 0) 
  Next a 
  ;- Remove checkbox for item 0
  SetGadgetItemData(1, 0, #CheckboxNo)
  ;- Remove checkbox for items 2 thru 5
  For i = 2 To 5 
    ;- We store the on/off switch
    SetGadgetItemData(1, i, #CheckboxNo)
  Next i 
  ;- Remove checkbox for items 9 thru 12
  For i = 9 To 12 
    ;- We store the on/off switch
    SetGadgetItemData(1, i, #CheckboxNo)
  Next i 
  SetGadgetItemState(1, 1, #PB_Tree_Expanded)
  SetGadgetItemState(1, 1, #PB_Tree_Checked)
  SetGadgetItemState(1, 8, #PB_Tree_Expanded)
  Repeat 
    event = WaitWindowEvent()
  Until  event = #PB_Event_CloseWindow 
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Thanks Sparks, a timely posting indeed! :)

An ingenious solution!

Right, better save this code before KCC gets his hands on it...
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Thanks to srod's example to allow checkboxes on explorertreegadgets (I know it's old), my backup for a mate is proceeding.

3 questions.

1. Given that explorertreegadgets don't have checkboxes without having that style, how do you detect if it is checked?

2. Does checking a box return an event in this case?

3. If I check a box and it has children, is there an easy way to recurse through and check its' children?

Recursion always causes me grief.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Not so easy fangles for several reasons.

1. ExplorerTrees do not use item numbers like regular tree gadgets. That is, you do not have items 0, 1, 2, ... etc. You are forced to use api handles instead. This means, for example, when the user alters a checkbox, you will not receive a nice item number, but an api handle instead!

2. Only vista / win 7 has a single message to detect when a stateimage within a tree-gadget has been changed (unlike ListIcons). Earlier versions require some api code to deal with hit-tests and keyboard selection. Not too difficult, but then not especially straight forward either.

3. Probably other reasons as well! :)

I could probably russle up some code for you, but you have to decide first how useful it is going to be with the above in mind?
Last edited by srod on Wed Apr 22, 2009 11:42 am, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

1. ExplorerTrees do not use item numbers like regular tree gadgets. That is, you do not have items 0, 1, 2, ... etc. You are forced to use api handles instead. This means, for example, when the user alters a checkbox, you will not receive a nice item number, but an api handle instead!
I suspected that might be the case. Having used other people's API substitutes in the past, I can turn it into a reuseable procedure once/if I understand it.
2. Only vista / win 7 has a single message to detect when a stateimage has been changed. Earlier versions require some api code to deal with hit-tests and keyboard selection. Not too difficult, but then not especially straight forward either.
That is going to be a problem. This program is going to have to work from XP and up.

Might have to tell him I am too tired (LOL!!) which I always am.

ExplorerTreegadgets seemed ideal at the time as you could have files and directories in the list and with the checkbox style applied, select files and/or directories to backup from the one gadget. I've seem many backup programs offer this but I guess they are completely ownerdrawn gadgets.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply