Page 1 of 1

Scroll Window Client Area The Short Cut

Posted: Fri May 14, 2010 6:39 pm
by RASHAD
Girl2.bmp needed

Code: Select all

Global yNewPos,yCurrentScroll,yDelta,xNewPos,xCurrentScroll,xDelta,Min,Max

Procedure WndProc(hwnd, uMsg, wParam, lParam)
 result = #PB_ProcessPureBasicEvents 

  Select uMsg
     
;     Case #WM_NOTIFY
;          UpdateWindow_(WindowID(0))
          
    Case #WM_HSCROLL          
      Select wParam & $FFFF
          Case #SB_LINELEFT
              If xCurrentScroll >= Min
                xNewPos = xCurrentScroll - 1
                xDelta = 1
              EndIf
              If xNewPos < Min
                 xNewPos = Min
              EndIf
      
          Case #SB_LINERIGHT
              If xCurrentScroll <= Max
                xNewPos = xCurrentScroll + 1
                xDelta = -1
              EndIf
              If xNewPos > Max
                 xNewPos = Max
              EndIf
              
              
;         Case #SB_THUMBPOSITION
;             xNewPos = wParam >> 16 & $FFFF

      
          Case #SB_THUMBTRACK
              xNewPos = wParam >> 16 & $FFFF
              If xNewPos > xCurrentScroll
                xDelta = -(xNewPos - xCurrentScroll)
              Else
                xDelta = xCurrentScroll - xNewPos
              EndIf              

      EndSelect
                    
    If xCurrentScroll <> xNewPos               
        xCurrentScroll = xNewPos 
      If xNewPos <= Max And xNewPos >= Min
          SetScrollPos_(WindowID(0),#SB_HORZ,xNewPos,1)
          ScrollWindowEx_(WindowID(0),xDelta,0,0,0,0,0,#SW_ERASE|#SW_INVALIDATE|#SW_SCROLLCHILDREN)
      EndIf
    EndIf                    
                    
 
    Case #WM_VSCROLL,#WM_MOUSEWHEEL 
      Select wParam & $FFFF
        Case #SB_LINEUP
            If yCurrentScroll >= Min
              If (wParam >> 16 & $FFFF) <> $FF88      ;For #WM_MOUSEWHEEL
                yNewPos = yCurrentScroll - 1
                yDelta = 1
              Else
                yNewPos = yCurrentScroll + 1
                yDelta = -1
              EndIf
            EndIf
            If yNewPos < Min
               yNewPos = Min
            EndIf
            If yNewPos > Max
               yNewPos = Max
            EndIf
    
        Case #SB_LINEDOWN
            If yCurrentScroll <= Max
            yNewPos = yCurrentScroll + 1
            yDelta = -1
            EndIf
            If yNewPos > Max
               yNewPos = Max
            EndIf
            
            
;       Case #SB_THUMBPOSITION
;           yNewPos = wParam >> 16 & $FFFF
        
        Case #SB_THUMBTRACK
            yNewPos = wParam >> 16 & $FFFF
            If yNewPos > yCurrentScroll
              yDelta = -(yNewPos - yCurrentScroll)
            Else
              yDelta = yCurrentScroll - yNewPos
            EndIf
                  
      EndSelect

      If yNewPos <> yCurrentScroll               
            yCurrentScroll = yNewPos
        If yNewPos <= Max And yNewPos >= Min
            SetScrollPos_(WindowID(0),#SB_VERT,yNewPos,1)
            ScrollWindowEx_(WindowID(0),0,yDelta,0,0,0,0,#SW_ERASE|#SW_INVALIDATE|#SW_SCROLLCHILDREN)
        EndIf
      EndIf

  EndSelect   
  ProcedureReturn result 
EndProcedure

Min = 0
Max = 1000

LoadImage(0, "girl2.bmp")
OpenWindow(0,0,0,800,600,"",#PB_Window_SystemMenu|#WS_HSCROLL|#WS_VSCROLL|#PB_Window_ScreenCentered)
SetWindowColor(0,$000000)
SetScrollRange_(WindowID(0),#SB_VERT,Min,Max,1)
SetScrollRange_(WindowID(0),#SB_HORZ,Min,Max,1)
ImageGadget(0,10,10,250,350, ImageID(0))
DisableGadget(0,1)


SetWindowCallback(@WndProc())

Repeat
  EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow

Edit: New Update

Re: Scroll Window Client Area The Short Cut

Posted: Fri May 14, 2010 7:10 pm
by srod
Well, nice try, but it really doesn't work here. You haven't set the scroll page length for one thing and it simply doesn't scroll properly here at all - seems to scroll backwards! And as for the flicker.... eeks!

Re: Scroll Window Client Area The Short Cut

Posted: Fri May 14, 2010 7:35 pm
by Fluid Byte
1.) It scrolls backwards
2.) Flickers real bad
3.) Why use ScrollWindowEx_() if you use it just for an image?
4.) Wrong forum? This was supposed for "Tips & Tricks", wasn't?

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 3:26 am
by RASHAD
Update
1. Scroll back to normal
2. Added MouseWheel support
3. Flicker minimized
4. Removed all not necessary code(was for original by MSDN)

Thank you guys for reporting srod & FB(yours are very pro)

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 10:49 am
by srod
Still scrolls backwards! In fact it doesn't scroll at all here until you drag the scrollbox! :) The flicker has gone though.

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 11:48 am
by RASHAD
@srod
I am confused with the scroll direction (we have the bar shaft and the arrows and the mousewheel )
You have the + & - do it and give us the right combination

And thank you again

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 11:50 am
by srod
E.g., when the user hits the scroll-down button, the client area is supposed to move up - not down!

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 12:07 pm
by RASHAD
But is what is happening here with me press the arrow up the client area moves down and vice versa
Except for the starting of the bar shaft because the imge at the most left top

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 12:13 pm
by srod
Ah, I see what you've done! :)

However, drag the vertical scroll-thumb downwards and of coure we expect to see the image disappear upwards... but that doesn't happen! Kind of 'un-natural' in a way! :wink:

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 12:19 pm
by RASHAD
You do not give up mate (24 hour on the net )
You are killing me
I just concentrated on the image not the the whole client area
Please srod do not answer that let it go

Re: Scroll Window Client Area The Short Cut

Posted: Mon May 17, 2010 12:21 pm
by srod
Well, all you need do is move the image up etc. :wink:

But I shall let it go as requested.

Re: Scroll Window Client Area The Short Cut

Posted: Fri Aug 27, 2010 6:08 am
by RASHAD
I forgot this post for long ,Sorry
First post updated
Bug fixed
Workaround for double click mouse event
Added new feature

Have fun