Page 1 of 1

Update :Custom ScrollAreaGadget [Windows]

Posted: Mon May 31, 2010 6:36 pm
by RASHAD

Code: Select all


Global xNewPos,xCurrentScroll,Bg_Brush


Procedure WndProc(hwnd, uMsg, wParam, lParam)

  If IsGadget(0)
      xCurrentScroll = GetGadgetAttribute(0,#PB_ScrollArea_X)             ;GetGadgetState(5)
  EndIf
  
  Result = #PB_ProcessPureBasicEvents

Select uMsg
        Case #WM_HSCROLL

            Select wParam & $FFFF

                Case #SB_PAGEUP 
                    xNewPos = xCurrentScroll - 1

                Case #SB_PAGEDOWN
                    xNewPos = xCurrentScroll + 1

                Case #SB_LINEUP 
                    xNewPos = xCurrentScroll - 1
  
                Case #SB_LINEDOWN 
                    xNewPos = xCurrentScroll + 1

                Case #SB_THUMBPOSITION 
                    xNewPos = wParam >> 16 & $FFFF
                    
           EndSelect
           
           SetGadgetAttribute(0,#PB_ScrollArea_X,xNewPos)
           SetGadgetState(5,xNewPos)
           
           
        Case #WM_CTLCOLORSCROLLBAR
             Result = Bg_Brush

  EndSelect

  ProcedureReturn Result
EndProcedure

ScrollBarHeight = 30  
  
If OpenWindow(0, 0, 0, 305, 130, "Custom ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ScrollAreaGadget(0, 10, 10, 285,116, 600, 80, 30)
    ShowScrollBar_(GadgetID(0), #SB_HORZ, 0)
    SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #WS_CLIPSIBLINGS)
    SetWindowPos_(GadgetID(0), #HWND_BOTTOM	, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    ButtonGadget  (1, 10, 10, 60, 60,"Button 1")
    ButtonGadget  (2, 80, 10, 60, 60,"Button 2")
    ButtonGadget  (3, 150, 10, 60, 60,"Button 3")
    CloseGadgetList()
    ScrollBarGadget(5, 12, WindowHeight(0) - ScrollBarHeight - 6, WindowWidth(0) - 22,ScrollBarHeight, 0,250,5)
    SetWindowLongPtr_(GadgetID(5), #GWL_STYLE, GetWindowLongPtr_(GadgetID(5), #GWL_STYLE) | #WS_CLIPSIBLINGS)
    SetWindowPos_(GadgetID(5), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    Bg_Brush = CreateSolidBrush_($93FFFE)
    SetWindowCallback(@WndProc())
    
    
  Repeat
    Select WaitWindowEvent()
      Case  #PB_Event_CloseWindow
        End
      Case  #PB_Event_Gadget
        Select EventGadget()
          Case 1
            MessageRequester("Info","Button 1 was pressed!",#PB_MessageRequester_Ok)
          Case 2
            MessageRequester("Info","Button 2 was pressed!",#PB_MessageRequester_Ok)
          Case 3
            MessageRequester("Info","Button 3 was pressed!",#PB_MessageRequester_Ok)
        EndSelect
    EndSelect
  ForEver
  DeleteObject_(Bg_Brush)
EndIf

I tested it with Windows 7 only for now

Have fun

Updated :Bug fixed

Re: Custom ScrollAreaGadget [Windows]

Posted: Mon May 31, 2010 6:57 pm
by PureLust
RASHAD wrote:I tested it with Windows 7 only for now

Have fun
If one uses the next/prev-Page area of the Scroll-Gadget, the scrolling does not work 100% correct (you will get a "delay" by changing the direction - at least under XP).

i.e.: just click 5 times the slider to the right (by clicking in the next/prev-Page area - not by clicking the arrows) . If you now click the slider to the left, you still scroll to the right one time.
You can see it better, if you increase the PageLenght while creating the Gadget with ScrollBarGadget().
Tested @ WinXP, SP3.

Greetz, PL.

Re: Custom ScrollAreaGadget [Windows]

Posted: Mon May 31, 2010 7:29 pm
by RASHAD
Prev. Post Updated

Re: Update :Custom ScrollAreaGadget [Windows]

Posted: Wed Jun 02, 2010 5:39 am
by RASHAD
For both Val & Hal ScrollBars
You can assign different width for Val and different height for Hal scrollbar

Code: Select all

Global xNewPos,yNewPos,xCurrentScroll,yCurrentScroll,Bg_Brush

ExamineDesktops()

Procedure WndProc(hwnd, uMsg, wParam, lParam)

  If IsGadget(0)
      xCurrentScroll = GetGadgetAttribute(0,#PB_ScrollArea_X)             ;GetGadgetState(5)
      yCurrentScroll = GetGadgetAttribute(0,#PB_ScrollArea_Y)
  EndIf
  
  Result = #PB_ProcessPureBasicEvents

     Select uMsg
     
        Case #WM_HSCROLL

            Select wParam & $FFFF

                Case #SB_PAGEUP 
                    xNewPos = xCurrentScroll - 1

                Case #SB_PAGEDOWN
                    xNewPos = xCurrentScroll + 1

                Case #SB_LINEUP 
                    xNewPos = xCurrentScroll - 1
  
                Case #SB_LINEDOWN 
                    xNewPos = xCurrentScroll + 1

                Case #SB_THUMBPOSITION 
                    xNewPos = wParam >> 16 & $FFFF
                    
           EndSelect
           
           SetGadgetAttribute(0,#PB_ScrollArea_X,xNewPos)
           SetGadgetState(5,xNewPos)
           
          Case #WM_VSCROLL,#WM_MOUSEWHEEL
  
            Select wParam & $FFFF
             
                Case #SB_PAGEUP 
                    yNewPos = yCurrentScroll - 1

                Case #SB_PAGEDOWN 
                    yNewPos = yCurrentScroll + 1

                Case #SB_LINEUP
                    If (wParam >> 16 & $FFFF) <> $FF88
                        yNewPos = yCurrentScroll - 1
                    Else
                        yNewPos = yCurrentScroll + 1
                    EndIf 

                Case #SB_LINEDOWN 
                    yNewPos = yCurrentScroll + 1

                Case #SB_THUMBPOSITION
                    yNewPos = wParam >> 16 & $FFFF
                    
          EndSelect
           
           SetGadgetAttribute(0,#PB_ScrollArea_Y,yNewPos)
           SetGadgetState(6,yNewPos)
           
           
        Case #WM_CTLCOLORSCROLLBAR
             Result = Bg_Brush

  EndSelect

  ProcedureReturn Result
EndProcedure


x = 10
y = 10
ScrollAreaWidth  = 580
ScrollAreaHeight = 380
ScrollBarHeight  = 25
ScrollBarWidth   = 25  
  
If OpenWindow(0, 0, 0, 600, 400, "Custom ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ScrollAreaGadget(0, x, y,ScrollAreaWidth,ScrollAreaHeight,DesktopWidth(0),DesktopHeight(0), 30)
    ShowScrollBar_(GadgetID(0), #SB_BOTH, 0)
    SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #WS_CLIPSIBLINGS)
    SetWindowPos_(GadgetID(0), #HWND_BOTTOM	, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    ButtonGadget  (1, 10, 10, 60, 60,"Button 1")
    ButtonGadget  (2, 80, 10, 60, 60,"Button 2")
    ButtonGadget  (3, 150, 10, 60, 60,"Button 3")
    CloseGadgetList()
    ScrollBarGadget(5, 10,390 - ScrollBarHeight,580 - ScrollBarWidth,ScrollBarHeight, 0,(5*DesktopWidth(0))/30,5)
    SetWindowPos_(GadgetID(5), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    ScrollBarGadget(6,ScrollAreaWidth + x - ScrollBarWidth,y,ScrollBarWidth,ScrollAreaHeight - ScrollBarHeight, 0,(5*DesktopHeight(0))/30,5,#PB_ScrollBar_Vertical)
    SetWindowPos_(GadgetID(6), #HWND_TOP, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    Bg_Brush = CreateSolidBrush_($93FFFE)
    SetWindowCallback(@WndProc())
    
    
  Repeat
    Select WaitWindowEvent()
      Case  #PB_Event_CloseWindow
        End
      Case  #PB_Event_Gadget
        Select EventGadget()
          Case 1
            MessageRequester("Info","Button 1 was pressed!",#PB_MessageRequester_Ok)
          Case 2
            MessageRequester("Info","Button 2 was pressed!",#PB_MessageRequester_Ok)
          Case 3
            MessageRequester("Info","Button 3 was pressed!",#PB_MessageRequester_Ok)
        EndSelect
    EndSelect
  ForEver
  DeleteObject_(Bg_Brush)
EndIf