Click here to Skip to main content
14,550,260 members

Improved mouse click handling for the slider control

Rate this:
4.55 (22 votes)
Please Sign up or sign in to vote.
4.55 (22 votes)
26 Dec 2002
Class that provides better mouse click handling for the standard windows slider control

The problem

I don't know if anyone has ever noticed how difficult it can be to select a value using the slider control. For instance this control:


When you try to change the setting by clicking at the 20 kHz tick mark, sometimes it doesn't move at all and if it does move, it'll first only move to the 50 kHz setting. Usually what happens is that the user will clicking a few time times and then eventually give up and just drag the thumb down.

This strange behaviour is actually caused by two separate bugs in the slider control.

Firstly, the hit region does not extend below the last tick mark:


So clicking just below the last tick mark results in the slider not moving at all

Secondly, the slider control apparently has been subclassed from the scrollbar control, and has inherited the scrollbar's mouse click behaviour. This means if you click on the column area it causes the slider to move down one page (which in the case of this example is only one position). While this behaviour is correct for the scrollbar control it is entirely inappropriate for the slider control. When I click on the 20 kHz value I expect it to move directly to the 20 kHz position, not to 50 kHz:



I have made a subclassed slider control to rectify these problems.

To use the code simply include the files NiceSlider.h & NiceSlider.cpp in your project, then in your dialog, or form class use class wizard to create a member variable for the slider control and replace CSliderCtrl with CNiceSliderCtrl:

#include "NiceSlider.h"

// CImprovedSliderDlg dialog

class CImprovedSliderDlg : public CDialog
// Construction
	CImprovedSliderDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	CNiceSliderCtrl	m_sliderImproved;


A special thanks to Daniel Frey whose round slider control class I used as a starting point for my class.

This problem with the slider control I have noticed in both Windows NT and Win9x. I have not checked if they have yet fixed it in Windows 2000, or XP.


  • First version!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

ed welch
Software Developer Astronautz
Spain Spain
After working in the software industry for many years, I've started my own games company that specialises in strategy games for mobile platforms.

Comments and Discussions

QuestionLicense terms Pin
Scott Bartine7-Dec-11 11:35
MemberScott Bartine7-Dec-11 11:35 
AnswerRe: License terms Pin
ed welch9-Dec-11 4:21
Membered welch9-Dec-11 4:21 
GeneralThanks!!! Pin
ave_want18-Nov-10 21:55
Memberave_want18-Nov-10 21:55 
GeneralThanks !! Pin
Kevin109230-Dec-09 19:59
MemberKevin109230-Dec-09 19:59 
GeneralThanks Pin
biocomp2-Apr-08 22:21
Memberbiocomp2-Apr-08 22:21 
GeneralThanks Pin
Member 36521604-Feb-08 6:04
MemberMember 36521604-Feb-08 6:04 
GeneralFix : Position Calc [modified] Pin
shijoong22-Aug-06 22:57
Membershijoong22-Aug-06 22:57 
Generalfix Pin
wheregone19-Mar-06 19:07
Memberwheregone19-Mar-06 19:07 
Questionhow to enable tooltips? Pin
zsabo29-Sep-05 22:00
Memberzsabo29-Sep-05 22:00 
QuestionHow about with WTL? Pin
jgoeke4-Jan-05 10:29
Memberjgoeke4-Jan-05 10:29 
GeneralRemoving Edge Pin
Balkrishna Talele15-Jul-04 19:35
MemberBalkrishna Talele15-Jul-04 19:35 
GeneralJust fine! Pin
Yasuhiko Yoshimura10-Sep-03 23:33
MemberYasuhiko Yoshimura10-Sep-03 23:33 
Generalbug fix Pin
nasu16-May-03 20:49
Membernasu16-May-03 20:49 
GeneralRe: bug fix Pin
ed welch19-May-03 22:50
Membered welch19-May-03 22:50 
GeneralOoops, I just noticed a bug... Pin
ed welch30-Dec-02 5:05
Membered welch30-Dec-02 5:05 
GeneralRe: Ooops, I just noticed a bug... Pin
nasu16-May-03 20:40
Membernasu16-May-03 20:40 
GeneralRe: Ooops, I just noticed a bug... Pin
ed welch19-May-03 22:39
Membered welch19-May-03 22:39 
GeneralRe: Ooops, I just noticed a bug... Pin
nasu20-May-03 7:20
Membernasu20-May-03 7:20 
GeneralMore on trackbars Pin
Todd C. Wilson27-Dec-02 6:16
MemberTodd C. Wilson27-Dec-02 6:16 
GeneralVery nice description of the problem Pin
Marc Clifton27-Dec-02 5:32
mvaMarc Clifton27-Dec-02 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 26 Dec 2002


23 bookmarked