Click here to Skip to main content
Licence 
First Posted 26 Dec 2002
Views 79,772
Bookmarked 20 times

Improved mouse click handling for the slider control

By | 26 Dec 2002 | Article
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:

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

About the Author

ed welch

Software Developer
Astronautz
Spain Spain

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionLicense terms PinmemberScott Bartine11:35 7 Dec '11  
AnswerRe: License terms Pinmembered welch4:21 9 Dec '11  
GeneralThanks!!! Pinmemberave_want21:55 18 Nov '10  
GeneralThanks !! PinmemberKevin109219:59 30 Dec '09  
GeneralThanks Pinmemberbiocomp22:21 2 Apr '08  
GeneralThanks PinmemberMember 36521606:04 4 Feb '08  
GeneralFix : Position Calc [modified] Pinmembershijoong22:57 22 Aug '06  
Generalfix Pinmemberwheregone19:07 19 Mar '06  
Questionhow to enable tooltips? Pinmemberzsabo22:00 29 Sep '05  
QuestionHow about with WTL? Pinmemberjgoeke10:29 4 Jan '05  
GeneralRemoving Edge PinmemberBalkrishna Talele19:35 15 Jul '04  
GeneralJust fine! PinmemberYasuhiko Yoshimura23:33 10 Sep '03  
Generalbug fix Pinmembernasu20:49 16 May '03  
GeneralRe: bug fix Pinmembered welch22:50 19 May '03  
GeneralOoops, I just noticed a bug... Pinmembered welch5:05 30 Dec '02  
GeneralRe: Ooops, I just noticed a bug... Pinmembernasu20:40 16 May '03  
GeneralRe: Ooops, I just noticed a bug... Pinmembered welch22:39 19 May '03  
GeneralRe: Ooops, I just noticed a bug... Pinmembernasu7:20 20 May '03  
GeneralMore on trackbars PinmemberT.Wilson6:16 27 Dec '02  
GeneralVery nice description of the problem PinmemberMarc Clifton5:32 27 Dec '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 27 Dec 2002
Article Copyright 2002 by ed welch
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid