Click here to Skip to main content
15,884,176 members
Articles / Desktop Programming / MFC

A Class to Combine Slider Control and Progress Bar Windows

Rate me:
Please Sign up or sign in to vote.
4.89/5 (31 votes)
23 Jan 2018CPOL2 min read 139.4K   7.2K   93  
An article on how to combine Slider Controls and Progress bar into one class using custom draw
//
//	Purpose:	Combines Slider control & Progress bar controls
//
//	Created:	03/11/2003
//	Updated:	07/01/2004
//
//	Author:		Cem KARACA			mfcem@ikikule.com
//									http://www.ikikule.com
//
//
//  THIS CODE AND THE APPLICATON IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//  ANY KIND, EITHER EXPRESSED OR IMPLIED.USE THIS CODE AND THE SOFTWARE
//	AT YOUR OWN RISK.
// 
//  � Copyright 2004 Cem KARACA.
//
//	Terms of use
//	
//	This software is freeware!
//	
#pragma once

#define WM_FREEZE	WM_USER+0xF003
// CProSliderCtrl

class CProSliderCtrl : public CSliderCtrl
{
	DECLARE_DYNAMIC(CProSliderCtrl)
public: // Progress Control functions
	// Gets the current lower and upper limits, or range, of the progress bar control.
	void _GetRange(int& nLower, int& nUpper);
	// Sets the upper and lower limits of the progress bar control's range and redraws the bar to reflect the new ranges.
	void _SetRange(short nLower, short nUpper);
	// Sets the upper and lower limits of the progress bar control's range and redraws the bar to reflect the new ranges.
	void _SetRange32(int nLower, int nUpper);
	// Sets the background color for the progress bar. 
	COLORREF _SetBkColor(COLORREF clrNew);
	// Sets the thumb color
	COLORREF _SetThumbColor(COLORREF clrNew);
	// Sets the channel color
	COLORREF _SetChColor(COLORREF clrNew);
	// Gets the current position of the progress bar.
	int _GetPos(void);
	// Advances the current position of a progress bar control by a specified increment and redraws the bar to reflect the new position.
	int _OffsetPos(int nPos);
	// Sets the current position for a progress bar control and redraws the bar to reflect the new position.
	int _SetPos(int nPos);
	// Specifies the step increment for a progress bar control.
	int _SetStep(int nStep);
	// Advances the current position for a progress bar control by the step increment and redraws the bar to reflect the new position.
	int _StepIt(void);
	// De/Freezes the slider and returns the prev. state
	BOOL Freeze(void);
	// Enables/Disables borders
	HRESULT _EnableBorders(BOOL bEnable=TRUE);
	BOOL _IsEnabled(void);
public:
	CProSliderCtrl();
	virtual ~CProSliderCtrl();
protected:
	DECLARE_MESSAGE_MAP()
	// General Purpose Draw Function
	void Draw(LPNMCUSTOMDRAW pNMCD);
	void RecursiveRect(CDC *pDC, CRect rc, COLORREF nClr, BOOL First=FALSE);
	void RecursiveChannel(CDC *pDC, CRect rc, COLORREF nClr,
		BOOL First=FALSE, BOOL Vertical=FALSE,BYTE StepSize=20);
protected:	// Progress Control variables
	// Progress bar background color
	COLORREF m_ProBkColor;
	// Progress bar color;
	COLORREF m_ProgressBarColor;
	// Progress bar ranges
	PBRANGE m_ProRange;	
	// Progress bar position
	int m_ProgressPos;
	// Step increment for Progress control
	int m_ProgressStep;
	// Direction, V/H
	DWORD m_Direction;
	// Thumb Color when mouse is over
	COLORREF m_ThClOver;
	// Thumb Color when mouse is out
	COLORREF m_ThClOut;
	// Thumb Color when mouse is pressed
	COLORREF m_ThClPre;
	// Thumb Default Color
	COLORREF m_ThClDef;
	// Borders
	BOOL m_bBorders;
	// Slider Freezed?
	BOOL m_bFreezed;
	// Temproray color storages
	COLORREF tmp1,tmp2;
	BOOL m_bBlink;
public:
	afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);
protected:
	// Draws the slider thumb
	HRESULT DrawSliderThumb(LPNMCUSTOMDRAW pNMCD);
	HRESULT DrawSliderBorder(LPNMCUSTOMDRAW pNMCD);
	HRESULT DrawSliderChannel(LPNMCUSTOMDRAW pNMCD);
	void SetThumbColor(COLORREF nClr);
public:
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Founder VeriTeknik B.V.
Netherlands Netherlands
Electrical & Electronic Engineer Ms.
Finished studying MS in Electrical & Electronics Eng. (2004).
Founder & Manager of VeriTech B.V. VeriTech.net

Comments and Discussions