like that:

The drawback of implementing custom Gadgets is that you can't use PB's standard
functions like GetGadgetState() to read changed settings, so you have to program your
own functions again using the API.
Take a look into my code example that generated the above snapshot. To create a
custom TrackBar you have to call the procedure CreateCustomTrackBar() and to read
the current value of a TrackBar you have to call the function GetControl32BitValue()
instead of GetGadgetState(). Not too complicated, isn't it?

Code: Select all
ImportC ""
CreateSliderControl(WindowRef.L, *BoundsRectangle, InitialValue.L, Minimum.L, Maximum.L, Orientation.L, TickMarksCount.U, LiveTracking.L, LiveTrackingCallback.L, *ControlRef)
GetControl32BitValue(ControlRef.L)
ShowControl(ControlRef.L)
EndImport
#NumCustomTrackBars = 5
; ----- Control Slider Orientation Constants
#kControlSliderPointsDownOrRight = 0
#kControlSliderPointsUpOrLeft = 1
#kControlSliderDoesNotPoint = 2
Structure Rect
Top.W
Left.W
Bottom.W
Right.W
EndStructure
Define Bounds.Rect
Define Info.S
Dim CustomTrackBar(#NumCustomTrackBars - 1)
ProcedureC CreateCustomTrackBar(WindowRef.L, x.W, y.W, Width.W, Height.W, Orientation.L, InitialValue.L, Minimum.L, Maximum.L)
Protected Bounds.Rect
Protected GadgetRef.L
Bounds\Left = x
Bounds\Top = y
Bounds\Right = x + Width
Bounds\Bottom = y + Height
If CreateSliderControl(WindowRef, @Bounds, InitialValue, Minimum, Maximum, Orientation, Maximum - Minimum + 1, #False, 0, @GadgetRef) = 0
ShowControl(GadgetRef)
ProcedureReturn GadgetRef
EndIf
EndProcedure
OpenWindow(0, 200, 100, 530, 200, "Custom TrackBars created via API", #PB_Window_SystemMenu)
; ----- Create 1st TrackBar (horizontal) with tick marks below
CustomTrackBar(0) = CreateCustomTrackBar(WindowID(0), 70, 20, 190, 20, #kControlSliderPointsUpOrLeft, 5, 0, 10)
TextGadget(0, 280, 20, 220, 20, "With tick marks above slider")
; ----- Create 2nd TrackBar (horizontal) with tick marks above
CustomTrackBar(1) = CreateCustomTrackBar(WindowID(0), 70, 60, 190, 20, #kControlSliderPointsDownOrRight, 10, 0, 20)
TextGadget(1, 280, 60, 220, 20, "With tick marks below slider")
; ----- Create 3rd TrackBar (horizontal) without tick marks
CustomTrackBar(2) = CreateCustomTrackBar(WindowID(0), 70, 100, 190, 20, #kControlSliderDoesNotPoint, 5, 0, 10)
TextGadget(2, 280, 100, 220, 20, "Without tick marks and pointer")
; ----- Create 4th TrackBar (vertical) with tick marks at right side
CustomTrackBar(3) = CreateCustomTrackBar(WindowID(0), 10, 10, 20, 180, #kControlSliderPointsDownOrRight, 10, 0, 20)
TextGadget(3, 40, 175, 220, 20, "With tick marks at right side")
; ----- Create 5th TrackBar (vertical) with tick marks at right side
CustomTrackBar(4) = CreateCustomTrackBar(WindowID(0), 500, 10, 20, 180, #kControlSliderPointsDownOrRight, 10, 0, 20)
TextGadget(4, 275, 175, 220, 20, "With tick marks at left side", #PB_Text_Right)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
; ----- Read the current values of the custom TrackBarGadgets and display them
For i = 1 To #NumCustomTrackBars
Info + "TrackBar " + Str(i) + ": " + Str(GetControl32BitValue(CustomTrackBar(i - 1))) + #CR$
Next i
CloseWindow(0)
MessageRequester("TrackBar settings", Info)