Page 1 of 1

How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 7:06 am
by AZJIO

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, 0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
; 							how to hide checkboxes
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
						Else
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 8:25 am
by jacdelad
Hi AZJIO,
this ist not possible (look at TVS_CHECKBOXES):

Code: Select all

https://learn.microsoft.com/en-us/windows/win32/controls/tree-view-control-window-styles
Version 5.80. Displays a check box even if no image is associated with the item.
Once a tree-view control is created with this style, the style cannot be removed.
...so this works only on rather old Windows versions.

BTW, you shouldn't use PureBasic constant for API calls, use the Windows constant instead. It worked this time, but this not always the case.

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 9:08 am
by BarryG
jacdelad wrote: Mon Jul 08, 2024 8:25 amthis ist not possible
What about this StackOverflow code -> https://stackoverflow.com/a/34320003/7908170

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 9:44 am
by Mindphazer
Hi,
in one of my applications, i display a treegadget and the user can choose to display checkboxes or not.
The only way i found is to free and redraw the treegadget with or without the #PB_Tree_CheckBoxes option.

If there's an easier way to do that, i'd be glad to know it :P

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 11:40 am
by jacdelad
BarryG wrote: Mon Jul 08, 2024 9:08 am
jacdelad wrote: Mon Jul 08, 2024 8:25 amthis ist not possible
What about this StackOverflow code -> https://stackoverflow.com/a/34320003/7908170
Microsoft themselves said it is not possible (anymore). The quaestion on stack overflow was asked 8 years ago, so maybe they tested it on Windows<Vista. However, I have Nightshift this week and my company is still idling, so I surely will have time to translate it to PureBasic test it (if nobody is doing it before). But I'm sure this won't work.

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 4:05 pm
by AZJIO
after cancellation, it is impossible to check the box, it does not visually disappear

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 4:10 pm
by RASHAD
One step forward

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700,#PB_Tree_CheckBoxes)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)

	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next

	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle	
               ImageList_SetIconSize_(imglist,16,16)
               SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
					  Else
							  ImageList_SetIconSize_(imglist,0,16)
                SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							  SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 9:59 pm
by jacdelad
RASHAD-GPTs idea is not bad. Combining it with the original code seems to work:

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, 0)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
; 							how to hide checkboxes
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
							  ImageList_SetIconSize_(imglist,0,16)
                SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							  SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
						Else
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Though I don't know whether real icons will be usable...

Re: How to hide checkboxes in a TreeGadget?

Posted: Mon Jul 08, 2024 11:57 pm
by RASHAD
1st step RASHAD
2nd step jacdelad
3rd step RASHAD
4th step ????????

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, #PB_Tree_CheckBoxes)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
              SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
              SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)
						Else
						  SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
						  SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,0)							
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf

Re: How to hide checkboxes in a TreeGadget?

Posted: Tue Jul 09, 2024 6:24 pm
by AZJIO
Thanks, I used this in my program (FileSizesList)

Re: How to hide checkboxes in a TreeGadget?

Posted: Tue Jul 09, 2024 9:41 pm
by jacdelad
BTW, I'm impressed that something, of which the Windows SDK tells us it is not possible, is possible with such a little trick. :mrgreen: