ScrollBarGadget Position

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

ScrollBarGadget Position

Post by geoff »

When a scroll bar is moved the new position can be obtained with GetGadgetState().
But this only seems to work when the scroll movement is complete and the left mouse button is released.

How can one get the scroll bar position continuously as it is moved?
This is needed to update a window content smoothly and continuously.

Is this already possible? If so, sorry for posting in the wish list.
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

A little Example by Danilo (posted in the German Forum a while ago)

Code: Select all

Procedure RealTimeScrollEvent(GadgetID,Pos) 
  ; Your stuff here, for each Scrollbar 
  Select GadgetID 

    Case GadgetID(1) ; Scrollbar 1 
      SetGadgetText(2,Str(Pos)) 

    Case GadgetID(3) ; Scrollbar 2 
      SetGadgetText(4,Str(Pos)) 

  EndSelect 
EndProcedure 


Procedure ScrollCallback(hWnd,Msg,wParam,lParam) 
  ; dont change this procedure 
  Shared DK_OldScrollCallback 
  If ((Msg = #WM_HSCROLL) Or (Msg = #WM_VSCROLL)) And (wParam & $FFFF) = #SB_THUMBTRACK 
    RealTimeScrollEvent(lParam,(wParam >> 16) & $FFFF) 
  EndIf 
  If DK_OldScrollCallback 
    ProcedureReturn CallWindowProc_(DK_OldScrollCallback,hWnd,Msg,wParam,lParam) 
  Else 
    ProcedureReturn 0 
  EndIf 
EndProcedure 

Procedure SetScrollbarCallback(GadgetNr) 
  ; dont change this procedure 
  Shared DK_OldScrollCallback 
  DK_OldScrollCallback = SetWindowLong_(GetParent_(GadgetID(GadgetNr)),#GWL_WNDPROC,@ScrollCallback()) 
EndProcedure 


OpenWindow(0,200,200,200,200,#PB_Window_SystemMenu,"ScrollIt!") 
  CreateGadgetList(WindowID()) 

  ScrollBarGadget(1,20,20,15,160,1,1000,100,#PB_ScrollBar_Vertical) 
  TextGadget(2,0,0,100,20,"1") 
  ScrollBarGadget(3,40,20,100,15,1,8000,1) 
  TextGadget(4,100,0,100,20,"1") 

  SetScrollbarCallback(1) ; Gadget 1, first  Scrollbar 
  SetScrollbarCallback(3) ; Gadget 3, second Scrollbar 

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

Thanks freedimension.

Since I posted this I have found an easier way.

Just look for WM_COMMAND messages in your normal callback routine (ie $111) and use the normal GetGadgetState() to retrieve the slider position.

This solves the problem because the callback routine executes whenever you move the mouse in the slider but your normal control loop does not run until your finger is lifted from the mouse button.
Post Reply