Hi all,
To help Terry, and becourse i wanted to have this feature, too
i've played around with Scrollbar controls, and this is what came
out of it:
Please let me know, if something doesn't work.
(tested with Win98se and WinXP)
Timo
Code: Select all
; ------------------------------------------------------------------------------------
; ScrollGadget:
;
; Makes scrollable Areas that can contain Gadgets, and other Controls.
; by Timo Harter
;
;
; Usage:
; *************************
; OpenScrollGadget(x, y, Width, Height, SizeX, SizeY, Flags, WindowID)
;
; x = X Position of the Area
; y = Y Position of the Area
; Width = Width of Area
; Height = Height of Area
; SizeX = Width of the Virtual Area that can be scrolled
; SizeY = Height of the Virtual Area that can be scrolled
; Flags = Can be one or more of those Values (combine them with '|')
;
; #ScrollBar_ScrollH Shows a horizontal Scrollbar
; #ScrollBar_ScrollV Shows a vertical Scrollbar
; #ScrollBar_Border Draw a Border around the scrolling Area
; #ScrollBar_ThickBorder Draw a thick border
;
; WindowID = ID of parent window (use WindowID() to get it)
;
; CloseScrollGadget() Call this, when you finished putting Gadgets in the Scroll Area
; If this Command isn't called, all following Gadgets are put inside the Scroll Area
;
; Note:
; ***********
;
; * Positions of Gadgets drawn inside a ScrollGadget are relative to the Position of the ScrollGadget, not to
; the Main Window.
;
; * You can create as much ScrollGadgets as you want.
;
; * To create a ScrollGadget in another ScrollGadget, use the Handle returned by the first ScrollGadget as
; WindowID for the other ScrollGadget.
;
; * To create a ScrollGadget inside a PanelGadget, create a Frame3dGadget() like this:
; hFrame.l = Frame3DGadget(), and use hFrame as WindowID for the ScrollGadget.
; You'll need to make the ScrollGadget 20 pixel smaller that the Frame3dGadget in order to
; see the Scrollbars.
;
; * For more information, see the Example below.
; ------------------------------------------------------------------------------------
; This is initial Stuff, copy it to the beginning of your code.
; ------------------------------------------------------------------------------------
Structure ScrollGadgetInfo
ScrollBars.l
*Previous.l
hParent.l
hPB.l
hMainWin.l
hWindow.l
hScrollV.l
hScrollH.l
Height.l
Width.l
SizeX.l
SizeY.l
PosX.l
PosY.l
EndStructure
NewList ScrollGadgets.ScrollGadgetInfo()
AddElement(ScrollGadgets())
Declare OpenScrollGadget(x, y, Width, Height, SizeX, SizeY, Flags, WindowID)
Declare CloseScrollGadget()
Declare WindowCallback(WindowID, Message, wParam, lParam)
#ScrollBar_ScrollH = 1
#ScrollBar_ScrollV = 2
#ScrollBar_Border = 4
#ScrollBar_ThickBorder = 8
; ------------------------------------------------------------------------------------
; End of initial code, following is a short example.
; ------------------------------------------------------------------------------------
If OpenWindow(0, 0, 0, 500, 500, #PB_Window_SystemMenu, "Scrollbar Example") = 0 ; Create Window
MessageRequester("","Windowerror!",0)
End
EndIf
CreateGadgetList(WindowID()) ; create some Gadgets
ButtonGadget(1, 10, 10, 140, 20, "Not scrolled Button!")
ButtonGadget(2, 160, 10, 100, 20, "Another Button!")
hScr.l = OpenScrollGadget(10, 40, 465, 400, 550, 700, #ScrollBar_ScrollH | #ScrollBar_ScrollV | #ScrollBar_Border, WindowID())
; creat ScrollGadget with Border
For i = 1 To 10 ; just some other Gadgets
ButtonGadget(i+2, 20, i*70-60, 140, 25, "Button Number "+Str(i+2))
Next i
OpenScrollGadget(200, 100, 80, 30, 250, 0, #ScrollBar_ScrollH, hScr.l) ; a scrollGadget inside a ScrollGadget
ButtonGadget(13, 0, 0, 250, 30, "A Loooooooooooooooooong Gadget!")
CloseScrollGadget() ; close the Gadget
CloseScrollGadget()
ButtonGadget(14, 10, 465, 100, 25, "not Scrolled") ; this Button will not be scrolled
Repeat ; main Loop
Event = WaitWindowEvent()
If Event = #PB_EventGadget
MessageRequester("Event","Button Number "+Str(EventGadgetID())+" pushed!",#MB_ICONINFORMATION)
EndIf
Until Event = #PB_EventCloseWindow
End
; ------------------------------------------------------------------------------------
; These are needed Procedures, put them at the End of your code, or in an IncludeFile
; ------------------------------------------------------------------------------------
Procedure OpenScrollGadget(x, y, Width, Height, SizeX, SizeY, Flags, WindowID)
Protected WinFlag.l, Previous.l, *pointer, ScrollBars.l
If SizeX WindowID()
SetWindowLong_(WindowID,#GWL_WNDPROC,GetWindowLong_(WindowID(),#GWL_WNDPROC))
EndIf
ScrollGadgets()\ScrollBars = ScrollBars
ProcedureReturn ScrollGadgets()\hWindow
EndProcedure
Procedure CloseScrollGadget()
Protected *poiner.l, ScrollBars.l
ScrollBars = ScrollGadgets()\ScrollBars - 1
If ScrollBars > 0
UseGadgetList(ScrollGadgets()\hPB)
Else
UseGadgetList(ScrollGAdgets()\hMainWin)
EndIf
*pointer = ScrollGadgets()\Previous
ChangeCurrentElement(ScrollGadgets(), *pointer)
ScrollGadgets()\ScrollBars = ScrollBars
EndProcedure
Procedure WindowCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_HSCROLL
If lParam #NULL
ResetList(ScrollGadgets())
Repeat: ne = NextElement(ScrollGadgets())
Until ScrollGadgets()\hScrollH = lParam Or ne = #FALSE
wLow = PeekW(@wParam)
wHi = PeekW(@wParam+2)
Select wLow
Case #SB_LEFT: ScrollGadgets()\PosX = 0
Case #SB_RIGHT: ScrollGadgets()\PosX = ScrollGadgets()\SizeX
Case #SB_LINELEFT: ScrollGadgets()\PosX + 10
Case #SB_LINERIGHT: ScrollGadgets()\PosX - 10
Case #SB_PAGELEFT: ScrollGadgets()\PosX + ScrollGadgets()\Width
Case #SB_PAGERIGHT: ScrollGadgets()\PosX - ScrollGadgets()\Width
Case #SB_THUMBPOSITION: ScrollGadgets()\PosX = -wHi
Case #SB_THUMBTRACK: ScrollGadgets()\PosX = -wHi
EndSelect
SetWindowPos_(ScrollGadgets()\hWindow, 0, ScrollGadgets()\PosX, ScrollGadgets()\PosY, 0, 0, #SWP_NOACTIVATE | #SWP_NOOWNERZORDER | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_SHOWWINDOW)
SetScrollPos_(ScrollGadgets()\hScrollH, #SB_CTL, -ScrollGadgets()\PosX, #TRUE)
result = 0
EndIf
Case #WM_VSCROLL
If lParam #NULL
ResetList(ScrollGadgets())
Repeat: ne = NextElement(ScrollGadgets())
Until ScrollGadgets()\hScrollV = lParam Or ne = #FALSE
wLow = PeekW(@wParam)
wHi = PeekW(@wParam+2)
Select wLow
Case #SB_TOP: ScrollGadgets()\PosY = 0
Case #SB_BOTTOM: ScrollGadgets()\PosY = ScrollGadgets()\SizeY
Case #SB_LINEUP: ScrollGadgets()\PosY + 10
Case #SB_LINEDOWN: ScrollGadgets()\PosY - 10
Case #SB_PAGEUP: ScrollGadgets()\PosY + ScrollGadgets()\Height
Case #SB_PAGEDOWN: ScrollGadgets()\PosY - ScrollGadgets()\Height
Case #SB_THUMBPOSITION: ScrollGadgets()\PosY = -wHi
Case #SB_THUMBTRACK: ScrollGadgets()\PosY = -wHi
EndSelect
SetWindowPos_(ScrollGadgets()\hWindow, 0, ScrollGadgets()\PosX, ScrollGadgets()\PosY, 0, 0, #SWP_NOACTIVATE | #SWP_NOOWNERZORDER | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_SHOWWINDOW)
SetScrollPos_(ScrollGadgets()\hScrollV, #SB_CTL, -ScrollGadgets()\PosY, #TRUE)
result = 0
EndIf
Default
EndSelect
ProcedureReturn Result
EndProcedure
; -----------------------------------------------------------------------------------
Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs and the universe trying to produce bigger and better idiots.
...So far, the universe is winning.