[SOLVED] Treeview item handle and item index nr (Windows)

Just starting out? Need help? Post your questions and find answers here.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Treeview item handle and item index nr (Windows)

Post by RASHAD »

Hi boddhi
I think you should use SetActiveGadget(0) OR click Lbutton first
Just checked with Windows 10 x64 (VB) and it works fine as it should be
Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Treeview item handle and item index nr (Windows)

Post by RASHAD »

Using Text Gadget

Code: Select all

OpenWindow(0,0,0,400,300,"TreeView ToolTips",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

TreeGadget(0,10,10,380,280)
SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE)|#TVS_TRACKSELECT)

For a = 0 To 10
  AddGadgetItem (0, -1, "Normal Item "+Str(a), 0, 0)
  AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
  AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
  AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
Next

TextGadget(1,-200,0,200,24,"",#SS_CENTERIMAGE)
SetGadgetColor(1,#PB_Gadget_BackColor,$7FE5FE)
SetGadgetColor(1,#PB_Gadget_FrontColor,$0000FF)

tv.TV_HITTESTINFO
SetActiveGadget(0)
Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
      EndSelect         
      
    Case #WM_MOUSEMOVE
      GetCursorPos_(@tv\pt)
      ScreenToClient_(GadgetID(0),@tv\pt)
      h = SendMessage_(GadgetID(0),#TVM_HITTEST,0,tv)
      id = SendMessage_(GadgetID(0),4395 ,h,0) - 1
      r.RECT\left = tv\hItem
      SendMessage_(GadgetID(0),#TVM_GETITEMRECT,1,r)
      If tv\pt\x <= r\right And tv\hItem > 0 And tv\hItem <> hItemOld
        Text$ =" Item "+Str(id)+" Sublevel : "+ Str(GetGadgetItemAttribute(0, id, #PB_Tree_SubLevel))
        SetGadgetText(1,text$)
        width = GadgetWidth(1,#PB_Gadget_RequiredSize)+4
        MoveWindow_(GadgetID(1),r\left+20,r\top,width,24,1)  
      Else
        MoveWindow_(GadgetID(1),0,0,0,0,1)         
      EndIf
      
  EndSelect
  
Until Quit = 1
End

Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Treeview item handle and item index nr (Windows)

Post by boddhi »

RASHAD wrote: I think you should use SetActiveGadget(0) OR click Lbutton first
Just checked with Windows 10 x64 (VB) and it works fine as it should be
Hi RASHAD,

Still regarding your code on this post, the tooltip only appears when the cursor is on the left edge of the treeview because "r\right" is always equal to 0, as shown in the screenshot:

Image

Contrary to what the MSDN doc says:
MSDN wrote: TVM_GETITEMRECT message

Wparam
Value specifying the portion of the item for which to retrieve the bounding rectangle. If this parameter is TRUE, the bounding rectangle includes only the text of the item. Otherwise, it includes the entire line that the item occupies in the tree-view control.
wParam set to 1 doesn't seem to take item text into account. I tried it with wParam=0 and got the same result.

PS:

Code: Select all

SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE)|#TVS_TRACKSELECT )
Thanks for the tip "TVS_TRACKSELECT" :wink:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Treeview item handle and item index nr (Windows)

Post by boddhi »

RASHAD wrote: Using Text Gadget
For the same reason, the textgadget is not displayed in the visible part of the window :( .
Image
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Treeview item handle and item index nr (Windows)

Post by RASHAD »

I will investigate the case thoroughly
Until then next is a work around

Code: Select all

OpenWindow(0,0,0,400,300,"TreeView ToolTips",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

TreeGadget(0,10,10,380,280)
SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE)|#TVS_TRACKSELECT)

For a = 0 To 10
  AddGadgetItem (0, -1, "Normal Item "+Str(a), 0, 0)
  AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
  AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
  AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
Next

TextGadget(1,-200,0,200,24,"",#SS_CENTER|#SS_CENTERIMAGE)
SetGadgetColor(1,#PB_Gadget_BackColor,$7FE5FE)
SetGadgetColor(1,#PB_Gadget_FrontColor,$0000FF)

tv.TV_HITTESTINFO
SetActiveGadget(0)
Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      Quit = 1
      
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          InvalidateRect_(WindowID(0),0,1)
      EndSelect         
      
    Case #WM_MOUSEMOVE
      GetCursorPos_(@tv\pt)
      ScreenToClient_(GadgetID(0),@tv\pt)
      h = SendMessage_(GadgetID(0),#TVM_HITTEST,0,tv)
      id = SendMessage_(GadgetID(0),4395 ,h,0) - 1
      If tv\pt\x < 150 And tv\hItem <> hItemOld
        Text$ =" Item "+Str(id)+" Sublevel : "+ Str(GetGadgetItemAttribute(0, id, #PB_Tree_SubLevel))
        SetGadgetText(1,text$)
        MoveWindow_(GadgetID(1),tv\pt\x+40,tv\pt\y,160,24,1)  
      Else
        MoveWindow_(GadgetID(1),0,0,0,0,1)         
      EndIf
      
  EndSelect
  
Until Quit = 1
End


Egypt my love
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Treeview item handle and item index nr (Windows)

Post by RASHAD »

See if the problem is solved

Code: Select all

 #TVM_MAPHTREEITEMTOACCID = #TV_FIRST + 43

LoadFont(0,"Georgia",12)
OpenWindow(0,0,0,400,300,"TreeView ToolTips",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

TreeGadget(0,10,10,380,280)
SetGadgetColor(0,#PB_Gadget_BackColor,0)
SetGadgetColor(0,#PB_Gadget_FrontColor,$059DEF)
SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE)|#TVS_TRACKSELECT )
For a = 0 To 10
  AddGadgetItem (0, -1, "Normal Item "+Str(a), 0, 0)
  AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
  AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
  AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
  AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
Next
ttip = CreateWindowEx_(0, "Tooltips_Class32", "", #TTS_ALWAYSTIP|#TTS_BALLOON, 0, 0, 0, 0, 0, 0, 0, 0)
SetWindowTheme_(ttip, @null.w, @null.w)
SendMessage_(ttip,#WM_SETFONT,FontID(0),0)
SendMessage_(ttip,#TTM_SETTIPTEXTCOLOR,$0202FD,0)
SendMessage_(ttip,#TTM_SETTIPBKCOLOR,$DCFFFF,0)
SendMessage_(ttip, #TTM_SETMAXTIPWIDTH, 0, 150)
SendMessage_(ttip, #TTM_SETDELAYTIME, #TTDT_AUTOMATIC,200)

ti.TOOLINFO
ti\cbSize   = SizeOf(ti)
ti\uFlags   = #TTF_IDISHWND | #TTF_SUBCLASS
ti\uId= GadgetID(0)

tv.TV_HITTESTINFO

r.RECT

Repeat
  Select WaitWindowEvent()     
    Case #PB_Event_CloseWindow
      Quit = 1       
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
      EndSelect         
      
    Case #WM_MOUSEMOVE
      GetCursorPos_(@tv\pt)
      ScreenToClient_(GadgetID(0),@tv\pt)
      h = SendMessage_(GadgetID(0),#TVM_HITTEST,0,tv)
      r\left = h
      SendMessage_(GadgetID(0),#TVM_GETITEMRECT,1,@r)
      If tv\pt\x <= r\right And tv\hItem > 0 And tv\hItem <> hItemOld
        SendMessage_(ttip, #TTM_DELTOOL, 0, ti)
        SendMessage_(GadgetID(0),#TVM_SELECTITEM,#TVGN_CARET,tv\hItem)
        Text$ ="ToolTip for Item "+Str(GetGadgetState(0))+" SubLevel : "+Str(GetGadgetItemAttribute(0, GetGadgetState(0), #PB_Tree_SubLevel ))
        SendMessage_(ttip, #TTM_SETDELAYTIME, #TTDT_INITIAL,10)
        ti\lpszText = @Text$
        SendMessage_(ttip, #TTM_ADDTOOL, 0, ti)
        hItemOld = tv\hItem
      EndIf
  EndSelect
Until Quit = 1
End


Edit : Code modified
Last edited by RASHAD on Wed Feb 19, 2025 5:01 am, edited 4 times in total.
Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Treeview item handle and item index nr (Windows)

Post by boddhi »

RASHAD wrote: See if the problem is solved
:( No visible changes
Image
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Treeview item handle and item index nr (Windows)

Post by RASHAD »

Previous post updated
Egypt my love
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Treeview item handle and item index nr (Windows)

Post by boddhi »

RASHAD wrote: Previous post updated
👏 Yes! It's finally working properly!
Once again, you've demonstraate that you're the Master of the Windows GUI APIs. :wink: :D

Just one suggestion: Remove the line

Code: Select all

SendMessage_(GadgetID(0),#TVM_SELECTITEM,#TVGN_CARET,tv\hItem)
to keep the behavior induced by the style #TVS_TRACKSELECT after a previous item selection.

I can now definitively tag this thread as solved :wink:
Thanks again, RASHAD.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Post Reply