CScrollBarEx is a simple MFC control derived from
CWnd, it can display scrollbar max, min, and current value itself.
Recently, in one of my projects, I needed one scrollbar control that can display max, min and current val itself. You know, Microsoft's scrollbar control can't display text, so I decided that I would code this control by myself. Now I completed this scrollbar control, and it is not so bad for VC++ beginner, I decided to share this control with all CodeProject workmates. I did not have a lot of time to work on this control, so I had to code it simply, but it satisfied my requirements. It has some features as follows:
- It is simple, and simple to use.
- It is similar to the main functions of MFC scrollbar control.
- It can display scrollbar max, min and current value.
Now the scrollbar control is here. Enjoy and please help me with your invaluable notes, bug reports, ideas, etc. that you think might improve the quality of this code.
Using the Code
Creating the Scrollbar Control
First we need to create a scrollbar control.
- Add ScrollBarEx.h and ScrollBarEx.cpp to your project.
#include " ScrollBarEx.h" to the top of header file of class in which you want to add scrollbar control.
- Add a member variable of type
- In your CPP file, use the
Create method of the member variable to create a scrollbar control.
CStatic *pStatic = (CStatic *)GetDlgItem(IDC_SCROLLBAR_STATIC);
m_ScrollBarEx.Create(WS_VISIBLE | WS_CHILD, rcScrollBar, this, 2000);
m_ScrollBarEx.SetScrollBarMinMaxValColor(RGB(0, 0, 0));
m_ScrollBarEx.SetScrollBarTextBkColor(RGB(255, 255, 0));
m_ScrollBarEx.SetScrollBarCurValColor(RGB(255, 0, 0));
- Scrollbar control notify message
When moving scrollbar control to any position, scrollbar control's parent window would receive scrollbar control's notify message, you can do like this.
afx_msg LRESULT OnScrollBarMsg(WPARAM wParam, LPARAM lParam);
LRESULT CScrollBarDemoDlg::OnScrollBarMsg(WPARAM wParam, LPARAM lParam)
double dblCurVal = *(double *)lParam;
TRACE("ScrollBar Cur Val = %f\n", dblCurVal);
Next to Update
This scrollbar control is simple. I know that it needs many other functions to complete it, but I had no time, so if you update it, please send an mail to me. Thank you.
- 2012/1/10 Created scrollbar control