Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / MFC

Text ScrollBar Control

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
17 Jan 2012CPOL2 min read 49.9K   1.8K   14  
CScrollBarEx is a simple MFC control derived from CWnd, it can display scrollbar max, min, and current value
#if !defined(AFX_SCROLLBAREX_H__5AF255D5_2DC1_4A9C_8501_13B93AF7F692__INCLUDED_)
#define AFX_SCROLLBAREX_H__5AF255D5_2DC1_4A9C_8501_13B93AF7F692__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ScrollBarEx.h : header file

#define		WM_SCROLLBAR_MSG			WM_USER + 100

//
enum
{
	TIMERID_SCROLLBAR = 100,
	TIMERID_LEFTBTN,
	TIMERID_RIGHTBTN,
	TIMERID_LEFTBTNHOVER,
	TIMERID_RIGHTBTNHOVER
};

enum
{
	BTN_NORMAL = 0,
	BTN_FLAT
};
/////////////////////////////////////////////////////////////////////////////
// CScrollBarEx window

class CScrollBarEx : public CWnd
{
// Construction
public:
	CScrollBarEx();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CScrollBarEx)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CScrollBarEx();

	// Generated message map functions
protected:
	//{{AFX_MSG(CScrollBarEx)
	afx_msg void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg UINT OnGetDlgCode();
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:
	BOOL Create(DWORD dwStyle, const RECT rect, CWnd *pParentWnd, UINT nID);
	
	double GetScrollBarCurVal();

	void SetScrollBarMinMaxVal(double dblMin, double dblMax);
	void SetScrollBarMinMaxValColor(COLORREF crMinMaxVal);

	void SetScrollBarCurVal(double dblSliderVal);
	void SetScrollBarCurValColor(COLORREF crCurVal);

	void SetScrollBarTextBkColor(COLORREF crBk);
	void SetScrollBarFillColor(COLORREF crFill);
	
	void SetPrecise(int nPrec);

private:
	BOOL RegisterWindowClass(void); // Make it work as custom control
	void DrawBk(CDC *pDC);
	void DrawDataText(CDC *pDC);
	void DrawLRButton(CDC *pDC);
	void DrawScrollZoneButton(CDC *pDC);
	void CalcRect();
//	void DrawScrollButton(CDC *pDC);
	void SendMsgToParentWnd();

private:
	CRect		m_rcClient;

	CRect		m_rcText;
	CRect		m_rcSBThumb;
	CRect		m_rcScrollBar;
	
	CRect		m_rcSBLBtn;
	CRect		m_rcSBRBtn;

	// text color and bak color
	COLORREF	m_crSbBk;
	COLORREF	m_crTextBk;
	COLORREF	m_crCurVal;
	COLORREF	m_crMaxMinVal;
	// 
	int			m_nPrecise;

	//
	double		m_dblCurVal;
	double		m_dblMax;
	double		m_dblMin;

	int			m_nLBtnStatus;
	int			m_nRBtnStatus;

	BOOL		m_bThumbPressed;
	BOOL		m_bSBPressed;

//	BOOL		m_bTimerProc;
	CPoint		m_ClickPoint;

	BOOL		m_bSBLBtnHover;
	BOOL		m_bSBRBtnHover;
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SCROLLBAREX_H__5AF255D5_2DC1_4A9C_8501_13B93AF7F692__INCLUDED_)

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
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions