Click here to Skip to main content
Click here to Skip to main content

CDoubleScrollBar: Scrollbars based on double values

, 15 Mar 2002
Rate this:
Please Sign up or sign in to vote.
A simple plug-in replacement for CScrollBar, which provides direct access to scrolling with double values.

A Demo progam using CDoubleScrollBar

Introduction

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 CScrollBar.

The code

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 int form...

double CDoubleScrollBar::GetScrollLimit();
    // Compared with ...
int CScrollBar::GetScrollLimit();
double  CDoubleScrollBar::GetScrollPos() const;
    // Compared with ...
int CScrollBar::GetScrollPos() const;
void CDoubleScrollBar::GetScrollRange(double * dMinPos, double * dMaxPos);
    // Compared with ...
void CScrollBar::GetScrollRange(LPINT lpMinPos,LPINT lpMaxPos) const;
double CDoubleScrollBar::SetScrollPos(double dPos, bool bRedraw = true);
    // Compared with ...
int CScrollBar::SetScrollPos(int nPos,BOOL bRedraw = TRUE);
void CDoubleScrollBar::SetScrollRange(double dMinPos, 
                        double dMaxPos, bool bRedraw = true);
    // Compared with ...
void CScrollBar::SetScrollRange(int nMinPos,
                 int nMaxPos,BOOL bRedraw = TRUE);

Note: Please do not attempt to use GetScrollInfo() and 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 int.

To provide the functionality that has been lost with Get/SetScrollInfo(), I have written three methods, which also make changing the scrollbar easier.

double  CDoubleScrollBar::GetPageSize();
void CDoubleScrollBar::SetPageSize(double dPageSize,bool bRedraw);
double CDoubleScrollBar::GetTrackPos();

double CDoubleScrollBar::GetPageSize();. This returns the size of the page (the block that you drag) in double value. This replaces the segment of code...

SCROLLINFO siTemp;
m_ScrollBar.GetScrollInfo(&siTemp,SIF_PAGE);
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 bRedraw is true. This replaces the segment of code...

SCROLLINFO siTemp;
siTemp.nPage = nPageSize;
siTemp.fMask = SIF_PAGE;
m_ScrollBar.SetScrollInfo(&siTemp, bRedraw);

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 OnHScroll()/OnVScroll()) ...

SCOLLINFO siTemp;
m_ScrollBar.GetScrollInfo(&siTemp,SIF_TRACKPOS);
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.

Limitations

The main limitation is that you cannot (as yet) create member values of CDoubleScrollBar as doubles and you have to use the extra functions to overcome the lack of a DOUBLESCROLLINFO structure.

Please comment and send bug reports / fixes here &| at dbh@cs.stir.ac.uk.

Enjoy.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

DavyBoy

United Kingdom United Kingdom
Started baby coding around 12 years ago (in Spec48K Basic), upgraded to AMOS (& AMOS Pro) on the Amiga. I have spent the past 4 years immersed in Java, JScript, C++ and for the past few months MFC. I am just finding out how fun Windows can really be :P !
 
Davy Boy Out

Comments and Discussions

 
GeneralNot accurate PinmemberTW4-Nov-03 1:37 
GeneralThank PinmemberYves11-Oct-03 13:39 
GeneralXP problem PinmemberFilbert Fox22-Jun-03 2:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 16 Mar 2002
Article Copyright 2002 by DavyBoy
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid