After recently adding scrollbars to my final year project, I realized that I needed to use a scrollbar which can recognize
double values instead of
ints. I checked through the MSDN archive, and could find no direct way of supporting this. So I decided to write my own class, derived from
Reading the MSDN, it informs me that the maximum range of
int values is 32767 (which I find highly skeptical, as their holding values are 32 bit), and so I have merely subdivided the range in
double, by the maximum number of
int values. This variable is editable,
nPrecision defined in the constructor.
The following methods are overridden, compared here with there original
double CDoubleScrollBar::GetScrollPos() const;
int CScrollBar::GetScrollPos() const;
void CDoubleScrollBar::GetScrollRange(double * dMinPos, double * dMaxPos);
void CScrollBar::GetScrollRange(LPINT lpMinPos,LPINT lpMaxPos) const;
double CDoubleScrollBar::SetScrollPos(double dPos, bool bRedraw = true);
int CScrollBar::SetScrollPos(int nPos,BOOL bRedraw = TRUE);
void CDoubleScrollBar::SetScrollRange(double dMinPos,
double dMaxPos, bool bRedraw = true);
void CScrollBar::SetScrollRange(int nMinPos,
int nMaxPos,BOOL bRedraw = TRUE);
Note: Please do not attempt to use
SetScrollInfo() to obtain information about the scrollbar, if you wish to obtain their
double values. These methods have not been overridden, and return the original values in
To provide the functionality that has been lost with
Get/SetScrollInfo(), I have written three methods, which also make changing the scrollbar easier.
void CDoubleScrollBar::SetPageSize(double dPageSize,bool bRedraw);
double CDoubleScrollBar::GetPageSize();. This returns the size of the page (the block that you drag) in
double value. This replaces the segment of code...
int nPageSize = siTemp.nPage;
void CDoubleScrollBar::SetPageSize(double dPageSize,bool bRedraw);. This sets the size of the page, and causes the scrollbar to be redrawn if
true. This replaces the segment of code...
siTemp.nPage = nPageSize;
siTemp.fMask = SIF_PAGE;
double CDoubleScrollBar::GetTrackPos();. This returns the position of the scrollbar when the user is tracking (
SB_THUMBTRACK). Using this method when the user is not tracking causes unpredictable output. It replaces the segment of code (found in
int nCurrentTrackPos = siTemp.nTrackPos;
Implementing this code in your project is quite simple. Just add the .cpp and .h files to your project,
#include "DoubleScrollBar.h" in your .h files which will use the DoubleScrollBars, and create away.
The main limitation is that you cannot (as yet) create member values of
doubles and you have to use the extra functions to overcome the lack of a
Please comment and send bug reports / fixes here &| at firstname.lastname@example.org.