Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trackbar using the mouse wheel
#1
Hey dear QMers!

With TBM_SETLINESIZE we can set the increment in the Trackbar's range using the arrow keys. How to set the same increment using the mouse wheel?

In the following example, I would like to change the increment to 0.5.

Thanks for any help.
Regards.

Function dTrackbar
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 msctls_trackbar32 0x54030000 0x0 20 20 96 16 ""
;4 Static 0x54000000 0x0 124 24 48 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

def TBM_SETLINESIZE WM_USER+23

int i
str s

double dMin=5.5
double dMax=77.5

double dStep=0.5

int iMin=Round(dMin*2)
int iMax=Round(dMax*2)

sel message
,case WM_INITDIALOG
,,s=dMin
,,s.setwintext(id(4 hDlg))
,,
,case WM_HSCROLL
,
,,if(wParam&0xffff=TB_ENDTRACK) ret
,,SendMessage id(3 hDlg) TBM_SETRANGE 0 MakeInt(iMin iMax);; MinTrack & max slider
,,SendMessage(id(3 hDlg) TBM_SETLINESIZE 0 1)

,,i = GetTrackbarInfo(id(3 hDlg))
,,double dResult=i/2.0
,,s=dResult
,,s.setwintext(id(4 hDlg))
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
Subclass the trackbar and change WM_MOUSEWHEEL to WM_KEYDOWN.

Function dTrackbar
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog"
;3 msctls_trackbar32 0x54030000 0x0 20 20 96 16 ""
;4 Static 0x54000000 0x0 124 24 48 12 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

int i
str s

double dMin=5.5
double dMax=77.5
double dStep=0.5

sel message
,case WM_INITDIALOG
,,SetWindowSubclass(id(3 hDlg) &sub.WndProc_Subclass 1 0)
,,SendMessage id(3 hDlg) TBM_SETRANGE 0 MakeInt(Round(dMin*2) Round(dMax*2));; MinTrack & max slider
,,;SendMessage(id(3 hDlg) TBM_SETLINESIZE 0 1)
,,s=dMin
,,s.setwintext(id(4 hDlg))
,,
,case WM_HSCROLL
,,if(wParam&0xffff=TB_ENDTRACK) ret
,,i = GetTrackbarInfo(id(3 hDlg))
,,double dResult=i/2.0
,,s=dResult
,,s.setwintext(id(4 hDlg))
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam

sel message
,case WM_MOUSEWHEEL
,if wParam&0xffff=0
,,message=WM_KEYDOWN
,,wParam=iif(wParam&0x100000000 VK_RIGHT VK_LEFT)

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)

ret R
#3
Wow! Very nice!

Thanks for your help.
Regards.


Forum Jump:


Users browsing this thread: 1 Guest(s)