Code : Tout sélectionner
#Class_TrackBar = "msctls_trackbar32"
Procedure.s GetGadgetClass(hGadget.l)
Protected Class.s
Class = Space(255)
GetClassName_(hGadget, @Class, 254)
ProcedureReturn Class
EndProcedure
Procedure.l GetMinTB(nBar.l)
If IsGadget(nBar) And GetGadgetClass(GadgetID(nBar)) = #Class_TrackBar
ProcedureReturn SendMessage_(GadgetID(nBar), #TBM_GETRANGEMIN, 0, 0)
EndIf
EndProcedure
Procedure.l GetMaxTB(nBar.l)
If IsGadget(nBar) And GetGadgetClass(GadgetID(nBar)) = #Class_TrackBar
ProcedureReturn SendMessage_(GadgetID(nBar), #TBM_GETRANGEMAX, 0, 0)
EndIf
EndProcedure
Procedure SetMinTB(nBar.l, val.l)
If IsGadget(nBar) And GetGadgetClass(GadgetID(nBar)) = #Class_TrackBar
ProcedureReturn SendMessage_(GadgetID(nBar), #TBM_SETRANGEMIN, 0, val)
EndIf
EndProcedure
Procedure SetMaxTB(nBar.l, val.l)
If IsGadget(nBar) And GetGadgetClass(GadgetID(nBar)) = #Class_TrackBar
ProcedureReturn SendMessage_(GadgetID(nBar), #TBM_SETRANGEMAX, 0, val)
EndIf
EndProcedure
Procedure ReplaceTrackBarCursor(nBar.l, nWin.l)
Protected curPos.Point, curWin.l
; On enregistre la fenetre courante
curWin = WindowID()
GetCursorPos_(curPos)
If IsWindow(nWin) And IsGadget(nBar) And GetGadgetClass(GadgetID(nBar)) = #Class_TrackBar
UseWindow(nWin)
If GadgetWidth(nBar) > GadgetHeight(nBar)
curPos\x = curPos\x - (WindowX() + GadgetX(nBar)+10)
SetGadgetState(nBar, ((curPos\x) * (GetMinTB(nBar)+GetMaxTB(nBar))) / (GadgetWidth(nBar)-20))
Else
curPos\y = curPos\y - (WindowY() + GadgetY(nBar)+10)
If GetWindowLong_(WindowID(), #GWL_STYLE) & #WS_POPUP <> #WS_POPUP
curPos\y - 20; (pr la barre de titre)
EndIf
SetGadgetState(nBar, (GetMinTB(nBar)+GetMaxTB(nBar)) - ((curPos\y) * (GetMinTB(nBar)+GetMaxTB(nBar))) / (GadgetHeight(nBar)-20))
EndIf
UseWindow(GetDlgCtrlID_(curWin)) ; On rend le focus à la fenetre
Else
Debug "gad/win not initialized"
EndIf
EndProcedure
If OpenWindow(0,0,0,320,200,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"CheckBoxGadget") And CreateGadgetList(WindowID(0))
TrackBarGadget(0, 10, 40,250, 20,-100,100)
SetGadgetState(0, 50)
Debug GetMinTB(0)
Debug GetMaxTB(0)
; ----------------
; Correction
; SetMinTB(0,-100)
; Debug GetMinTB(0)
; Debug GetMaxTB(0)
; SetGadgetState(0, 50) ; Mettre en commentaire le SetGadgetState() au dessus
; ----------------
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf