Click here to Skip to main content
15,885,435 members
Articles / Desktop Programming / MFC
Article

Transparent CSliderCtrl Class

Rate me:
Please Sign up or sign in to vote.
4.54/5 (6 votes)
14 Nov 2002CPOL 139.7K   8.9K   47   16
A MFC Transparent CSliderCtrl class

sliders.jpg

Introduction

This is a MFC transparent slider class. As it uses CSliderCtrl as its base class it can be used as a replacement class for any CSliderCtrl object. Tic marks are fully supported as can be seen in the screen shot above. To use, add this class to your project. Add your sliders to your project normally, then change the CSliderCtrl type in your .h file to CMySliderControl and #include the MySliderControl.h file. Once compiled your sliders will be transparent and if you have auto tics set then these too will show.

Update

V2.0 Re-wrote parts of the class. Added the ability to redraw the controls when the backgrounds had changed. Added custom transparent channel and custom thumb with optional colours. The demo source has been updated to show the background changing.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: DrawTransparent() question Pin
David Cole30-Jul-04 7:00
David Cole30-Jul-04 7:00 
AnswerRe: DrawTransparent() question Pin
dhclark3-Nov-10 8:11
dhclark3-Nov-10 8:11 
QuestionBetter way to know vertical from horizontal? Pin
Harold Bamford20-Nov-02 17:27
Harold Bamford20-Nov-02 17:27 
AnswerRe: Better way to know vertical from horizontal? Pin
Nic Wilson21-Nov-02 11:18
Nic Wilson21-Nov-02 11:18 
Harold Bamford wrote:
In your code for DrawChannel(), you ask if there is a better way to determine if the control is vertical or horizontal. Try:

Great! I could not find that anywhere I will give it a try!

Harold Bamford wrote:
It looks like the goal of DrawChannel() is merely to capture the background bitmap and then finish the channel. Wouldn't it be easier to just capture the background in OnCustomDraw() and set *pResult = CDRF_DODEFAULT;

The class is unfinished and this is skeleton code for those who wish to alter the channel, some users do not know how to do this. I also like the type of channel this draws, I have expanded it further to fill the channel with various colours to the left, right or both sides of the slider sort of like a progress bar built in.
I will upload changes soon.


Harold Bamford wrote:
And while I'm asking dumb questions, why do you use the DC for the parent window rather than the current window?

The parent DC holds the background image we use to make the control transparent.

Nic
GeneralChanging the background image Pin
Atlantys22-Sep-02 7:51
Atlantys22-Sep-02 7:51 

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.