Post by Walt Decker on Jan 10, 2021 16:59:03 GMT -5
I have added a system scroll bar function to SCROLLWIDG.
The following demo plus SCROLLWIDG is contained in the attached zip file.
SYSTEM_SCROLL_BARS.ZIP (34.11 KB)
If you have questions or problems please let me know.
SB.HORZ = 0
SB.VERT = 1
SB.CTL = 2
SB.BOTH = 3
SS.CENTER = HEXDEC("&H00000001")
SS.CENTERIMAGE = HEXDEC("&H00000200")
SS.SUNKEN = HEXDEC("&H00001000")
WS.VSCROLL = HEXDEC("&H00200000")
WS.HSCROLL = HEXDEC("&H00100000")
WS.EX.TRANSPARENT = HEXDEC("&H00000020")
SW.HIDE = 0
SW.SHOW = 5
OPEN "SCROLLWIDG" FOR DLL AS #SCRL
STRUCT tRect, _
X AS LONG, _
Y AS LONG, _
X1 AS LONG, _
Y1 AS LONG
STRUCT ScrlVarbs, _
ScrlType AS LONG, _ '<--- SB.BOTH or SB.VERT or SB.HORZ
WinSzx AS LONG, _ '<--- Width of window(usually the client area)
WinSzy AS LONG, _ '<--- Height of window(usually the client area)
RangeX AS LONG, _ '<--- Range value of horizontal scroll bar
RangeY AS LONG, _ '<--- Range value of vertical scroll bar
PageSzx AS LONG, _ '<--- Horizontal page size
PageSzy AS LONG, _ '<--- Vertical page size
StepSzx AS LONG, _ '<--- Horizontal step size
StepSzy AS LONG '<--- Vertical step size
'=================================================================================
' NOTES!!!
'=================================================================================
' WinSzx, WinSzy are usually the client area of the window after the system
' scroll bars are added
' PageSzx, PageSzy determine the scroll amount when the body of the scroll bar
' is clicked. These also govern the maximum position of the scroll bar thumb,
' i. e. scroll box. MS defines the maximum scroll position as:
' MaxScrollPos = MaxRangeValue - (PageSize - 1)
' RangeX, RangeY determine the range overwhich the scroll box is active.
' RangeX, RangeY should be set to RangeX, RangeY + MaxScrollPos
' StepSzx, StepSzy determine the amount of scrolling when a scroll bar arrow is
' clicked.
'=================================================================================
UpperLeftX = 300
UpperRightX = 200
WindowWidth = 300
WindowHdight = 300
'<----------------- SET UP SYSTEM SCROLL BAR PARAMETERS ---------------------->
ScrlVarbs.ScrlType.struct = SB.HORZ
ScrlVarbs.WinSzx.struct = 300
ScrlVarbs.WinSzy.struct = 330
ScrlVarbs.RangeX.struct = 310
ScrlVarbs.RangeY.struct = 310
ScrlVarbs.PageSzx.struct = 10
ScrlVarbs.PageSzy.struct = 50
ScrlVarbs.StepSzx.struct = 15
ScrlVarbs.StepSzy.struct = 25
STYLEBITS #WIN.STAT, SS.CENTER OR SS.CENTERIMAGE OR SS.SUNKEN, 0, WS.EX.TRANSPARENT, 0
STATICTEXT #WIN.STAT, "PETER PIPER", 10, 2, 200, 150
'=================================================================================
' Here I have defined two system scroll base. Only one will be active because
' when I set up the scroll bar parameters I only defined the horizontal bar
'=================================================================================
STYLEBITS #WIN, WS.VSCROLL OR WS.HSCROLL, 0, 0, 0
TEXTEDITOR #WIN.ED, 300, 0, 250, 250
OPEN "SCROLL TEST" FOR WINDOW AS #WIN
PRINT #WIN, "RESIZEHANDLER SIZEIT"
PRINT #WIN, "TRAPCLOSE STOPIT"
WinHndl = HWND(#WIN)
'<------------- ACITVATE THE SYSTEM SCROLL BARS --------------------->
CALLDLL #SCRL, "FN_InitScroll", WinHndl AS ULONG, _ '<--- Handle of window
ScrlVarbs AS STRUCT, _ '<--- Scroll bar parameters
0 AS LONG, _ '<--- Zero: initialize the
_ 'function;
_ '> zero: add a window
_ '-1 remove a window
_ '< -1 remove all windows
RetVal AS LONG 'Result: # of windows activated
WAIT
END
'----------------------------------------------------------------------------------
'----------------------------------------------------------------------------------
SUB STOPIT Hndl$
'===================================================================================
' CLEAR THE SCROLL INFORMATION FOR THIS WINDOW
' THIS HAS TO BE DONE FOR EACH WINDOW FOR WHICH
' SYSTEM SCROLL BARS ARE DEFINED
'
' YOU CAN USE THIS FUNCTION AT ANY TIME
' TO CLEAR THE SCROLL BAR INFO FOR A
' PARTICULAR WINDOW
'===================================================================================
CALLDLL #SCRL, "FN_InitScroll", 0 AS ULONG, 0 AS ULONG, _
-7 AS LONG, RetVal AS LONG
CLOSE #SCRL
CLOSE #WIN
END
END SUB
'----------------------------------------------------------------------------------
'----------------------------------------------------------------------------------
SUB SIZEIT Hndl$
'=================================================================================
' LB autonatically repositions the controls when resizing. Therefore, let the
' function know that the window is resized so it can set the scroll parameters
' accordingly. SEE NOTE BELOW
'=================================================================================
WinHndl = HWND(#WIN)
CALLDLL #SCRL, "UpDateScroll", WinHndl AS ULONG, RetVal AS VOID
END SUB
'=================================================================================
' NOTE!!!
'=================================================================================
' You can update the scroll parameters youself by defining a SCROLLINFO structure,
' using the User32 DLL and calling GetScrollInfo() to retrieve the current scroll
' info, doing the appropriate calculations, setting the members of the structure and
' then calling the SetScrollInfo() function.
'----------------------------------------------------------------------------------
'----------------------------------------------------------------------------------