Click here to Skip to main content
13,896,005 members
Click here to Skip to main content
Add your own
alternative version

Stats

101.8K views
26.1K downloads
23 bookmarked
Posted 26 Dec 2002
Licenced

Improved mouse click handling for the slider control

, 26 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Class that provides better mouse click handling for the standard windows slider control
<!-- Download Links --> <!-- Add the rest of your HTML here -->

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:

Slider

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:

Slider

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:

Slider

Solution

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
public:
	CImprovedSliderDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CImprovedSliderDlg)
	enum { IDD = IDD_IMPROVEDSLIDER_DIALOG };
	CNiceSliderCtrl	m_sliderImproved;

Notes

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.

History

  • First version!

License

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

Share

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.

You may also be interested in...

Pro

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
protectorMarc 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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190306.1 | Last Updated 27 Dec 2002
Article Copyright 2002 by ed welch
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid