PureBasic Forum
http://forums.purebasic.com/english/

How to obtain number of element at top of scrolling window
http://forums.purebasic.com/english/viewtopic.php?f=13&t=73021
Page 1 of 1

Author:  Blue [ Fri Jun 14, 2019 6:22 am ]
Post subject:  How to obtain number of element at top of scrolling window

Sorry for the clumsy wording of the question...

I'm pretty sure I saw this question asked and answered before, but I don't even know how to formulate my search intelligently enough to get an answer. I've tried — in vain — all I could think of.

Since words won't come to mind, allow me to use a picture :
Image

Author:  RASHAD [ Fri Jun 14, 2019 8:07 am ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Hello Blue
Code:
OpenWindow(0,200,200,400,150,"Title", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

TreeGadget(1,0,0,400,150)
For t=1 To 50
  AddGadgetItem(1,-1,"item : "+Str(t))
Next
 
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
          Quit = 1
         
    Case #WM_NCMOUSEMOVE
        Position = SendMessage_(GadgetID(1), #WM_NCHITTEST, 0, DesktopMouseY()<<16 + DesktopMouseX())
        Select Position
          Case #HTVSCROLL
            item = GetScrollPos_(GadgetID(1), #SB_VERT)+1
            If item <> olditem             
              Debug "First Visible Item  = " + Str(item)
            EndIf
            olditem = item
        EndSelect
       
     
    Case #WM_KEYUP
        If GetActiveGadget() = 1 And (EventwParam() = 38 Or EventwParam() = 40)
          item = GetScrollPos_(GadgetID(1), #SB_VERT)+1
          If item <> olditem             
            Debug "First Visible Item  = " + Str(item)
          EndIf
          olditem = item
        EndIf         
  EndSelect
Until Quit = 1

Author:  Shardik [ Fri Jun 14, 2019 9:13 am ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Blue wrote:
I'm pretty sure I saw this question asked and answered before, but I don't even know how to formulate my search intelligently enough to get an answer. I've tried — in vain — all I could think of.

RASHAD already posted two examples in this thread from 2013... :wink:

And you posted already a similar question on how to detect the top visible row in a ListViewGadget in this thread. There I posted a cross-platform solution. I reduced the example to Windows-only code and modified it for the TreeGadget:
Code:
Procedure.I GetVisibleTopRow(ListIconID.I)
  Protected Item.TVITEM

  Item\mask = #TVIF_PARAM
  Item\hItem = SendMessage_(GadgetID(ListIconID), #TVM_GETNEXTITEM,
    #TVGN_FIRSTVISIBLE, GadgetItemID(ListIconID, 0))
  SendMessage_(GadgetID(TreeGadgetID), #TVM_GETITEM, 0, @Item)

  ProcedureReturn Item\lParam
EndProcedure

OpenWindow(0, 100, 100, 200, 155, "")
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 55)
ButtonGadget(1, 10, WindowHeight(0) - 35, WindowWidth(0) - 20, 25,
  "Get current top row")

For i = 1 To 50
  AddGadgetItem(0, -1, "Item " + Str(i))
Next i

SetWindowTitle(0, "Visible top row: " + Str(GetVisibleTopRow(0) + 1))

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        SetWindowTitle(0, "Visible top row: " + Str(GetVisibleTopRow(0) + 1))
      EndIf
  EndSelect
ForEver

Author:  C87 [ Fri Jun 14, 2019 9:21 am ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Hello Blue, Having seen your post, I'm interested to know which software you used to show your example with the graphics and text added?

Also, have to say the solutions to your problem are absolutely first class. As it is so often the case in the PureB forum.

Cheers, C87

Author:  RASHAD [ Fri Jun 14, 2019 9:25 am ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Thanks Shardik :P
I did not remember any
I should save my posts and the other forum members posts with the URL.
Bad

Thanks also for your snippet

Author:  infratec [ Fri Jun 14, 2019 11:54 am ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Extended version:
Code:
EnableExplicit


Procedure.i GetVisibleFirstTreeItem(TreeGadget.i)
 
  Protected Item.TVITEM

  Item\mask = #TVIF_PARAM
  Item\hItem = SendMessage_(GadgetID(TreeGadget), #TVM_GETNEXTITEM, #TVGN_FIRSTVISIBLE, GadgetItemID(TreeGadget, 0))
  SendMessage_(GadgetID(TreeGadget), #TVM_GETITEM, 0, @Item)
 
  ProcedureReturn Item\lParam
 
EndProcedure



Procedure.i GetVisibleTreeCount(TreeGadget.i)
 
  ProcedureReturn SendMessage_(GadgetID(TreeGadget), #TVM_GETVISIBLECOUNT, 0, 0)
 
EndProcedure


Macro SetTitle()
  Count = GetVisibleTreeCount(0)
  SetWindowTitle(0, "Visible top row: " + Str(GetVisibleFirstTreeItem(0) + 1) + " " + Str(GetVisibleFirstTreeItem(0) + Count)) 
EndMacro


Define i.i, Count.i


OpenWindow(0, 100, 100, 200, 155, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
WindowBounds(0, 200, 155, 200, #PB_Ignore)
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 55)
ButtonGadget(1, 10, WindowHeight(0) - 35, WindowWidth(0) - 20, 25, "Get current top row")

For i = 1 To 50
  AddGadgetItem(0, -1, "Item " + Str(i))
Next i

SetTitle()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        SetTitle()
      EndIf
    Case #PB_Event_SizeWindow
      ResizeGadget(0, 10, 10, #PB_Ignore, WindowHeight(0) - 55)
      ResizeGadget(1, 10, WindowHeight(0) - 35, #PB_Ignore, #PB_Ignore)
      SetTitle()
  EndSelect
ForEver

Author:  PeDe [ Fri Jun 14, 2019 12:11 pm ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

C87 wrote:
Hello Blue, Having seen your post, I'm interested to know which software you used to show your example with the graphics and text added?

I think Blue already mentioned it in another thread, it's "FastStone Capture v9". I like to use it, it also works well on very old PCs.
Edit: viewtopic.php?p=537823#p537823

Peter

Author:  Blue [ Fri Jun 14, 2019 2:28 pm ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Thank you to each of you.
With your enlightening contributions, I now have everything I need.
But they illustrate PB's major issue : i don't even have to think anymore! :shock:
Others do the thinking for me, and they do it so much better. :D
Seriously, though, had I searched for the word item instead of element, I would have found what I was looking for.

A special invitation to Shardik : there's a position open as Memory Manager in my brain. It's been vacant for a while now. It's yours for the asking... Meanwhile, your shocking exposé of my old post forced me to rediscover the "View your posts" function at the top right of each page. Very useful. Now, if I can only remember to use it....

Author:  Blue [ Fri Jun 14, 2019 10:36 pm ]
Post subject:  Re: How to obtain number of element at top of scrolling wind

Note to Shardik
Very interesting and imaginative solution, the way you use the window title as a display for the result that you're tracking. That never occurred to me before now, but I can see that, as a fast and dirty solution, it's hard to beat.

Thanks for a very interesting idea.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/