Date: 02-16-2022
Return to Index
created by gbSnippets
'====================================================================
' Declares
'--------------------------------------------------------------------
#COMPILE EXE
#DIM ALL
'------------------------------------------------
%USEMACROS = 1
#INCLUDE "WIN32API.INC"
#INCLUDE "COMMCTRL.INC"
'------------------------------------------------
%IDC_TRACKBAR1 = 200
MACRO TRACKBAR = "msctls_trackbar32"
'====================================================================
' Program entrance
'--------------------------------------------------------------------
FUNCTION PBMAIN () AS LONG
LOCAL hDlg AS DWORD
DIALOG NEW 0, "TrackBar test",,, 220, 140, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
'------------------------------------------------------------------
InitCommonControls
CONTROL ADD TRACKBAR, hDlg, %IDC_TRACKBAR1, "", 5, 5, 210, 20, _
%WS_CHILD OR %WS_VISIBLE OR %TBS_AUTOTICKS
CONTROL SEND hDlg, %IDC_TRACKBAR1, %TBM_SETRANGE, 0, MAK(LONG, 0, 100) ' range
CONTROL SEND hDlg, %IDC_TRACKBAR1, %TBM_SETTICFREQ, 5, 1 ' interval frequency
'------------------------------------------------------------------
CONTROL ADD BUTTON, hDlg, %IDOK, "&Ok", 112, 122, 50, 14
CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Quit", 166, 122, 50, 14
'------------------------------------------------------------------
DIALOG SHOW MODAL hDlg CALL DlgProc
END FUNCTION
'====================================================================
' Main Dialog procedure
'--------------------------------------------------------------------
CALLBACK FUNCTION DlgProc() AS LONG
'------------------------------------------------------------------
LOCAL lPos AS LONG
SELECT CASE CB.MSG
CASE %WM_INITDIALOG ' <- sent right before dialog is shown
CASE %WM_HSCROLL ' sent on trackbar scrollpos change
IF CB.LPARAM = GetDlgItem(CB.HNDL, %IDC_TRACKBAR1) THEN 'if correct control
CONTROL SEND CB.HNDL, %IDC_TRACKBAR1, %TBM_GETPOS, 0, 0 TO lPos 'get pos
DIALOG SET TEXT CB.HNDL, FORMAT$(lPos) ' show pos
END IF
CASE %WM_COMMAND
SELECT CASE CB.CTL
CASE %IDOK
IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
CONTROL SEND CB.HNDL, %IDC_TRACKBAR1, %TBM_GETPOS, 0, 0 TO lPos
MSGBOX "TrackBar pos = " + FORMAT$(lPos) ' .. or do whatever
END IF
CASE %IDCANCEL
IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN 'end prog
DIALOG END CB.HNDL
END IF
END SELECT
END SELECT
END FUNCTION
'gbs_01223
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm