PB Special ExplorerTreeGadget() {Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

PB Special ExplorerTreeGadget() {Windows]

Post by RASHAD »

Hi all
Hi KCC :)
The next should satisfy your requirement (I hope)
You can colorize any item with any colors
Enable selecting color in the next ROUND :D

Code: Select all

#TV_FIRST = $1100
#TVM_MAPACCIDTOHTREEITEM = (#TV_FIRST + 42)
#TVM_MAPHTREEITEMTOACCID = (#TV_FIRST + 43)

Global selitem,selitem2

Procedure winCB(hWnd, uMsg, wParam, lParam)
  Protected result, row
  Protected *TVCDHeader.NMTVCUSTOMDRAW
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *pnmh.NMHDR = lParam
      Select *pnmh\code
        Case #NM_CUSTOMDRAW
          *TVCDHeader.NMTVCUSTOMDRAW = lParam
          Select *TVCDHeader\nmcd\dwDrawStage
            Case #CDDS_PREPAINT
              result = #CDRF_NOTIFYITEMDRAW
            Case #CDDS_ITEMPREPAINT
              row = *TVCDHeader\nmcd\dwItemSpec 
              If row = selitem Or row = selitem2
                *TVCDHeader\clrTextBk = $00FF00
                *TVCDHeader\clrText = $0000FF
              Else
                *TVCDHeader\clrTextBk = $FFFFFF
                *TVCDHeader\clrText = $FF0000
              EndIf
              If *TVCDHeader\nmcd\uItemState & #CDIS_SELECTED
                *TVCDHeader\clrTextBk = $F39502
                *TVCDHeader\clrText = $FFFFFF
              EndIf
              result = #CDRF_DODEFAULT
          EndSelect
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0, 0, 0, 400, 500, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,0)
ExplorerTreeGadget(0, 10, 10, 380, 480, "c:\*.*", #PB_Explorer_AlwaysShowSelection)
selitem = SendMessage_(GadgetID(0), #TVM_MAPACCIDTOHTREEITEM,10,0)
selitem2 = SendMessage_(GadgetID(0), #TVM_MAPACCIDTOHTREEITEM,11,0)
SetWindowCallback(@winCB())
SetActiveGadget(0)
;InvalidateRect_(GadgetID(0),0,1)
Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      Quit = 1
      
  EndSelect
Until Quit = 1

Edit :Added Select item coloring
Last edited by RASHAD on Wed Jul 12, 2023 8:31 pm, edited 1 time in total.
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PB Special ExplorerTreeGadget() {Windows]

Post by Kwai chang caine »

Wahooouhhh !!!

What word can be say in front of this fireworks of API ??? :shock:
I knew that the great RASHAD was not going to give up in the face of adversity and was going to bring him to heel this ExplorerTreeGaget of misfortune :mrgreen:
Thanks a lot my millennium friend for create this miracle for little KCC 8)

Image

Three questions come to me :?:

1/ Why i'm again forcing to enable the Xp theme ? :| (You have see i have thinking to enable it this time :mrgreen: )
2/ Why the first drive C is in the index 8 ? :shock:
3/ How can i change color of an index expanded between 8 and 9 ?
ImageThe happiness is a road...
Not a destination
AZJIO
Addict
Addict
Posts: 2175
Joined: Sun May 14, 2017 1:48 am

Re: PB Special ExplorerTreeGadget() {Windows]

Post by AZJIO »

Code: Select all

#TV_FIRST = $1100
#TVM_MAPACCIDTOHTREEITEM = (#TV_FIRST + 42)
#TVM_MAPHTREEITEMTOACCID = (#TV_FIRST + 43)

Global selitem, selitem2

Procedure winCB(hWnd, uMsg, wParam, lParam)
	Protected result, row
	Protected *TVCDHeader.NMTVCUSTOMDRAW
	result = #PB_ProcessPureBasicEvents
	Select uMsg
		Case #WM_NOTIFY
			*pnmh.NMHDR = lParam
			Select *pnmh\code
				Case #NM_CUSTOMDRAW
					*TVCDHeader.NMTVCUSTOMDRAW = lParam
					Select *TVCDHeader\nmcd\dwDrawStage
						Case #CDDS_PREPAINT
							result = #CDRF_NOTIFYITEMDRAW
						Case #CDDS_ITEMPREPAINT
							row = *TVCDHeader\nmcd\dwItemSpec
							If row = selitem
								*TVCDHeader\clrTextBk = $008800
								*TVCDHeader\clrText = $00FFFF
							Else
								*TVCDHeader\clrTextBk = $FFFFFF
								*TVCDHeader\clrText = $880000
							EndIf
							result = #CDRF_DODEFAULT
					EndSelect
			EndSelect
	EndSelect
	ProcedureReturn result
EndProcedure

OpenWindow(0, 0, 0, 400, 500, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0, 0)
ExplorerTreeGadget(0, 10, 10, 380, 480, "c:\*.*", #PB_Explorer_AlwaysShowSelection)
InvalidateRect_(GadgetID(0), 0, 1)
SetWindowCallback(@winCB())
Repeat
	Select WaitWindowEvent(1)
		Case #PB_Event_CloseWindow
			Quit = 1
		Case #PB_Event_Gadget
			Select EventGadget()
				Case 0
					If EventType() = #PB_EventType_LeftClick
						selitem = SendMessage_(GadgetID(0), #TVM_GETNEXTITEM, #TVGN_CARET, 0)
						InvalidateRect_(GadgetID(0), 0, 1)
					EndIf
			EndSelect
	EndSelect
Until Quit = 1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: PB Special ExplorerTreeGadget() {Windows]

Post by RASHAD »

Hi KCC
1- For XP theme https://learn.microsoft.com/en-us/windo ... ohtreeitem
You need XP theme when using #TVM_MAPACCIDTOHTREEITEM and\or #TVM_MAPACCIDTOHTREEITEM
See MSDN remark

2- When enumerate the gadget all items you will discover that there are 7 rounds for Windows usage only

3- I will try to add the items ID in a simple way (just give me some time :) )
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: PB Special ExplorerTreeGadget() {Windows]

Post by RASHAD »

Previous post updated
Select item as it should be
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB Special ExplorerTreeGadget() {Windows]

Post by Fangbeast »

I think we need to convince MS to add in a KCC_ API with an excitement level variable:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: PB Special ExplorerTreeGadget() {Windows]

Post by RASHAD »

Hi Fang
with an excitement level variable
:mrgreen:
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB Special ExplorerTreeGadget() {Windows]

Post by Fangbeast »

RASHAD wrote: Thu Jul 13, 2023 3:03 am Hi Fang
with an excitement level variable
:mrgreen:
/me bows to the mighty wizard, teaching the kcc apprentice is a full time job for a wizard:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PB Special ExplorerTreeGadget() {Windows]

Post by Kwai chang caine »

Thanks a lot for yours explanations 8)
mAPIster wrote:You need XP theme when using #TVM_MAPACCIDTOHTREEITEM and\or #TVM_MAPACCIDTOHTREEITEM
See MSDN remark
Ok i have understand (Yes i know..it's a miracle :mrgreen: )
mAPIster wrote:When enumerate the gadget all items you will discover that there are 7 rounds for Windows usage only
Euuhhh !!! not really understand :oops: but if you say that...t's is right :mrgreen:
The most important it's on all the machines of the world it's the same behavior :wink:
mAPIster wrote:Previous post updated
Select item as it should be
I have not understand that too :oops:
When i run your code, the drive "C:" is already expanded
Then...if i want change the color of the "Canoscan" folder...how can i do because it is between 9 and 10 :|

Image
Fangbeast wrote:I think we need to convince MS to add in a KCC_ API with an excitement level variable:):)
Yes..you have right :lol:
Fangbeast wrote:/me bows to the mighty wizard, teaching the kcc apprentice is a full time job for a wizard:):)
You have again right, I have lost count of the number of nice members "Sparkie, Netmaestro, Srod, Celtic, etc ..." who have abandoned this quest :oops:

Image
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: PB Special ExplorerTreeGadget() {Windows]

Post by RASHAD »

Hi KCC
1- Make sure that the target folder is visible (CanoScan)
2- Execute RUN

Code: Select all

#TV_FIRST = $1100
#TVM_MAPACCIDTOHTREEITEM = (#TV_FIRST + 42)
#TVM_MAPHTREEITEMTOACCID = (#TV_FIRST + 43)

Global selitem,selitem2,selitem3

Procedure.s GetItemText(TV_H) 
  text.s = Space(#MAX_PATH) 
  pitem.TV_ITEM 
  pitem\mask = #TVIF_TEXT 
  pitem\hItem = SendMessage_(TV_H, #TVM_GETNEXTITEM, #TVGN_CARET,0) 
  pitem\pszText = @text 
  pitem\cchTextMax = #MAX_PATH 
  If (pitem\hItem) 
    SendMessage_(TV_H, #TVM_GETITEM, 0, @pitem) 
    ProcedureReturn PeekS(pitem\pszText)
  EndIf 
EndProcedure

Procedure winCB(hWnd, uMsg, wParam, lParam)
  Protected result, row
  Protected *TVCDHeader.NMTVCUSTOMDRAW
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *pnmh.NMHDR = lParam
      Select *pnmh\code
        Case #NM_CUSTOMDRAW
          *TVCDHeader.NMTVCUSTOMDRAW = lParam
          Select *TVCDHeader\nmcd\dwDrawStage
            Case #CDDS_PREPAINT
              result = #CDRF_NOTIFYITEMDRAW
            Case #CDDS_ITEMPREPAINT
              If *TVCDHeader\nmcd\uItemState & #CDIS_SELECTED
                *TVCDHeader\clrTextBk = $F39502
                *TVCDHeader\clrText = $FFFFFF
              Else
                row = *TVCDHeader\nmcd\dwItemSpec 
                If row = selitem Or row = selitem2 Or row = selitem3
                  *TVCDHeader\clrTextBk = $00FF00
                  *TVCDHeader\clrText = $0000FF
                Else
                  *TVCDHeader\clrTextBk = $FFFFFF
                  *TVCDHeader\clrText = $FF0000
                EndIf
              EndIf
              
              result = #CDRF_DODEFAULT
          EndSelect
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0, 0, 0, 400, 500, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,0)
ExplorerTreeGadget(0, 10, 10, 380, 450, "C:\*.*", #PB_Explorer_AlwaysShowSelection)
ButtonGadget(1,10,470,80,24,"RUN")
selitem = SendMessage_(GadgetID(0), #TVM_MAPACCIDTOHTREEITEM,10,0)
selitem2 = SendMessage_(GadgetID(0), #TVM_MAPACCIDTOHTREEITEM,11,0)
SetWindowCallback(@winCB())
InvalidateRect_(GadgetID(0),0,1)
list_Count = SendMessage_(GadgetID(0), #TVM_GETCOUNT,0,0)
itemH = SendMessage_(GadgetID(0), #TVM_GETNEXTITEM, #TVGN_FIRSTVISIBLE,0) 
Repeat
  Select WaitWindowEvent(1)
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          HideGadget(0,1)
          list_Count = SendMessage_(GadgetID(0), #TVM_GETCOUNT,0,0)
          For n = 0 To list_Count
            mselitem = SendMessage_(GadgetID(0), #TVM_MAPACCIDTOHTREEITEM,n,0)
            If Not mselitem
              list_Count + 1
            EndIf
            If mselitem
              SendMessage_(GadgetID(0), #TVM_SELECTITEM,#TVGN_CARET,mselitem)
              If GetItemText(GadgetID(0)) = "CanoScan"
                selitem3 = mselitem
              EndIf
            EndIf
          Next
          SendMessage_(GadgetID(0), #TVM_SELECTITEM,#TVGN_CARET,itemH)
          HideGadget(0,0) 
      EndSelect      
      
  EndSelect
Until Quit = 1

Egypt my love
Post Reply