ScrollBar events only on release

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ScrollBar events only on release

Post by srod »

Try this :

Code: Select all

Global gOldProc 

Procedure WndProc(WindowID, Msg.i, wParam.i, lParam.i)
  result = CallWindowProc_(gOldProc, WindowID, Msg, wParam, lParam)
  Select Msg
    Case #WM_HSCROLL
      scrollCode = wParam & $ffff
      If scrollCode <> #SB_THUMBPOSITION And scrollCode <> #SB_ENDSCROLL
        Debug GetGadgetState(0)
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

W = 512
H = 384
OpenWindow(0, 0, 0, W, H, "", #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget)

ScrollBarGadget(0, 10, 10, 200, 17, 0, 5, 1)

gOldProc = SetWindowLongPtr_(WindowID(0), #GWLP_WNDPROC, @WndProc())

Repeat
  Event = WaitWindowEvent()
  Select Event
    Case #PB_Event_CloseWindow
      CloseWindow(0)
      Break
  EndSelect
ForEver
Here, the sublass proc calls the previous handler (the one installed by PB) to handle, in particular, the scrolling events. PB's handler will use SetScrollInfo_() to actually move the scrollthumb etc. and our procedure simply retrieves this new value via GetGadgetState(). Comment out the result = ... line and you will see that no movement of the scrollthumb takes place (tracking aside) which is the default behaviour for Windows.
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: ScrollBar events only on release

Post by Trond »

Wow, thank you! :!: :!:

I tried a PB window callback, and I tried subclassing the gadget, but I didn't think of subclassing the window. That being said, subclassing the gadget works, when I use your technique of calling the old callback at the start instead of at the end. I never would have figured that out.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ScrollBar events only on release

Post by srod »

Trond wrote:Wow, thank you! :!: :!:

I tried a PB window callback, and I tried subclassing the gadget, but I didn't think of subclassing the window. That being said, subclassing the gadget works, when I use your technique of calling the old callback at the start instead of at the end. I never would have figured that out.
Yes I do that so that PB can move the scrollbox for us, otherwise GetGadgetState() will return the incorrect value. Personally, I don't call the old callback at all for #WM_HSCROLL and instead move the scrollbox myself the appropriate distance using SetScrollInfo_() etc.
I may look like a mule, but I'm not a complete ass.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: ScrollBar events only on release

Post by charvista »

@Trond
It looks like you asked the same question as me, in following your other topic http://www.purebasic.fr/english/viewtop ... 88#p369888 (ScrollBarGadget can't reach max?).
DoubleDutch gave me an answer that gave me a solution from RASHAD through a search in the forum: http://www.purebasic.fr/english/viewtop ... nt#p353306.
The difference with srod's solution is that RASHAD's code is portable (no APIs), but using a simple Thread.
Code below is from RASHAD, I modified it to have two scrollbars, and see if it can work with one Thread.

Code: Select all

;(c) Rashad 2011-05-22
; this will show in 'real-time' the current scrollbar position

Procedure Scrollbar(parameter)
    Repeat   
        SetGadgetText(1,Str(GetGadgetState(2)))
        SetGadgetText(4,Str(GetGadgetState(5)))
        Delay(40)
    ForEver
    
EndProcedure

OpenWindow(0, 0, 0, 305, 140, "ScrollBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    Vstart.i=50
    TextGadget       (0,  10,15, 220,  20, "VScrollBar Position : ",#PB_Text_Right)
    TextGadget       (1,  230,15, 20,  20, Str(Vstart),#PB_Text_Right)
    ScrollBarGadget  (2, 270, 10,  25, 120 ,0, 101, 1, #PB_ScrollBar_Vertical)
    SetGadgetState   (2,Vstart)
    
    Hstart.i=20
    TextGadget       (3,  0,90, 120,  20, "HScrollBar Position : ",#PB_Text_Right)
    TextGadget       (4,  120,90, 20,  20, Str(Hstart),#PB_Text_Right)
    ScrollBarGadget  (5, 0, 110,  270, 20 ,0, 101, 1)
    SetGadgetState   (5,Hstart)
    
    AddKeyboardShortcut(0, #PB_Shortcut_Up,10)
    AddKeyboardShortcut(0, #PB_Shortcut_Down,11)
    Thread = CreateThread(@Scrollbar(), 15)
    ThreadPriority(Thread, 1)
    Repeat
        Select WaitWindowEvent(1)     
            Case #PB_Event_CloseWindow
                Quit = 1       
                
            Case #PB_Event_Menu
                Select EventMenu()
                    Case 10
                        SetGadgetState(2,GetGadgetState(2) - 1)
                        SetGadgetText(1,Str(GetGadgetState(2)))
                        
                    Case 11
                        SetGadgetState(2,GetGadgetState(2) + 1)
                        SetGadgetText(1,Str(GetGadgetState(2)))
                        
                EndSelect
                
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case 2
                        
                EndSelect       
                
        EndSelect
    Until Quit = 1
CloseWindow(0)

Different approaches, same result.
Cheers!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: ScrollBar events only on release

Post by RASHAD »

Using Windows CallBack

Code: Select all

Global Backg1,Backg2,OldVPos,OldHPos

Backg1 = CreateSolidBrush_($BDFFFF)
Backg2 = CreateSolidBrush_($DFFFDD)

Procedure WndProc(hwnd, uMsg, wParam, lParam)  
  result = #PB_ProcessPureBasicEvents
  Select uMsg
 
    Case #WM_CTLCOLORSCROLLBAR
        If lParam = GadgetID(0)
          Result = Backg1
        Else
          Result = Backg2
        EndIf          

    Case #WM_MOUSEWHEEL
      If (wParam >> 16 & $FFFF) <> $FF88
        SetGadgetState(1,GetGadgetState(1) - 1)
      Else
        SetGadgetState(1,GetGadgetState(1) + 1)
      EndIf
      
    Case #WM_KEYDOWN ,#WM_MENUSELECT
        
        Select wParam
            Case #VK_UP
              SetGadgetState(1,GetGadgetState(1) - 1)
              
            Case #VK_DOWN
              SetGadgetState(1,GetGadgetState(1) + 1)
            
            Case #VK_LEFT
              SetGadgetState(0,GetGadgetState(0) - 1)
            
            Case #VK_RIGHT
              SetGadgetState(0,GetGadgetState(0) + 1)            
           
        EndSelect                  
  EndSelect
  
        If IsGadget(0) And OldHPos <> GetGadgetState(0)
           OldHPOs = GetGadgetState(0)
           Debug "H.ScrollBar Pos.: "+Str(OldHPos)
        ElseIf IsGadget(1) And OldVPos <> GetGadgetState(1)
           OldVPOs = GetGadgetState(1)
           Debug "V.ScrollBar Pos.: "+Str(OldVPos)
        EndIf
  
  ProcedureReturn result 
EndProcedure

OpenWindow(0, 0, 0, 300, 250, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
ScrollBarGadget(0, 10, 10,200,18, 0, 100, 1)
ScrollBarGadget(1, 10, 40, 18,200, 0, 100, 1,#PB_ScrollBar_Vertical)
Frame3DGadget(2, 9, 9, 203, 21, "",#PB_Frame3D_Double)
Frame3DGadget(3, 9, 39, 21, 203, "",#PB_Frame3D_Double)
SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
        
        Case 1

      EndSelect
       
    Case #PB_Event_CloseWindow
      Quit = 1
      
  EndSelect
Until Quit = 1

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: ScrollBar events only on release

Post by Kwai chang caine »

Rashad wrote:Using Windows CallBack
Waoouuuh !!! :shock: 8)
ImageThe happiness is a road...
Not a destination
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: ScrollBar events only on release

Post by charvista »

Waoouuuh !!! :shock: 8) :mrgreen: Rashad said once, KCC and me, we are trouble makers hahaha :lol:
Seriously now 8) . Rashad, excellent example. Nicely presented with CreateSolidBrush_ and Frame3DGadget. :D
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ScrollBar events only on release

Post by srod »

An 'expensive' way to check for scroll events. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ScrollBar events only on release

Post by Shardik »

charvista wrote:The difference with srod's solution is that RASHAD's code is portable (no APIs), but using a simple Thread.
Did you take a look into my cross-platform example for Windows,
Linux and MacOS which uses specific API calls on each platform
and demonstrates live scrolling on all platforms by scrolling an
image?
http://www.purebasic.fr/english/viewtop ... 45&start=2
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: ScrollBar events only on release

Post by charvista »

@Shardik
I have taken a deep look at it. Thank you very much for the example with a picture, which is very useful.
Now it is your turn to take a look at my reply there as I made some important corrections.
http://www.purebasic.fr/english/viewtop ... =2#p370251
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: ScrollBar events only on release

Post by collectordave »

You can roll your own and get whatever events you want at any mouse event etc.

Try this
http://www.purebasic.fr/english/viewtop ... 12&t=67411

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply