Scroll Window Client Area The Short Cut

Windows specific forum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Scroll Window Client Area The Short Cut

Post 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
Last edited by RASHAD on Fri Aug 27, 2010 6:06 am, edited 5 times in total.
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Scroll Window Client Area The Short Cut

Post 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!
I may look like a mule, but I'm not a complete ass.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Scroll Window Client Area The Short Cut

Post 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?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Scroll Window Client Area The Short Cut

Post 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)
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Scroll Window Client Area The Short Cut

Post by srod »

Still scrolls backwards! In fact it doesn't scroll at all here until you drag the scrollbox! :) The flicker has gone though.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Scroll Window Client Area The Short Cut

Post 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
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Scroll Window Client Area The Short Cut

Post by srod »

E.g., when the user hits the scroll-down button, the client area is supposed to move up - not down!
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Scroll Window Client Area The Short Cut

Post 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
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Scroll Window Client Area The Short Cut

Post 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:
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Scroll Window Client Area The Short Cut

Post 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
Egypt my love
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Scroll Window Client Area The Short Cut

Post by srod »

Well, all you need do is move the image up etc. :wink:

But I shall let it go as requested.
I may look like a mule, but I'm not a complete ass.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: Scroll Window Client Area The Short Cut

Post 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
Egypt my love
Post Reply