It is currently Tue Oct 22, 2019 4:21 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: How to obtain number of element at top of scrolling window
PostPosted: Fri Jun 14, 2019 6:22 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 673
Location: Canada
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

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 8:07 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
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

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 9:13 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 9:21 am 
Offline
User
User

Joined: Mon Jul 17, 2017 7:22 am
Posts: 66
Location: Cotswolds England
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

_________________
If it's falling over......just remember the computer is never wrong!


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 9:25 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3429
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

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 11:54 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4364
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 12:11 pm 
Offline
User
User

Joined: Sun Nov 26, 2017 3:13 pm
Posts: 17
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 2:28 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 673
Location: Canada
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....

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to obtain number of element at top of scrolling wind
PostPosted: Fri Jun 14, 2019 10:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 4:41 am
Posts: 673
Location: Canada
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.

_________________
"That's not a bug..." said the programmer. "...It's a feature! "
"Oh! I see..." replied the blind man.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye