fSCROLLBAR


Quick Data

Header file:scrollbar.h
Object name:fSCROLLBAR
Object index:1 of 1 Object

General Description

You can see the scrollbar everywhere around Windows - it is used to show more of a particular thing - be that a list, a text document, an image, or something else like that. It's a useful component, and here it is.

Now this component doesn't work 100% correctly, but by manually specifying it's location, you can solve most of the problems with it. However, don't let this put you off - this component is still very useful.

This component is derived from _GUIBASE, and inherits the properties from that.


Primary Options


Name Description Value

There are no Primary properties for this component. Just use sbUsual or 0 (Zero).

Secondary Options


Name Description Value

sbNormal This is the usual scrollbar style. It creates a scrollbar that is... well... a scrollbar. By default I think the scrollbar is vertical, but you can use the options mentioned later to specify the actual orientation. You may well like to combine this style with other styles to achieve the right effect. AvWind

The following options are a little different. Whereas the above options are a mixture of styles to create one type of object, the following styles are by themselves. You can mix them up to make more customised objects. You mix the styles with the OR (|) operator. You can even mix them with the above styles to enhance them further. Mix and match away!
sbAlignBottom
sbAlignLeft
sbAlignRight
sbAlignTop
I think you will find these styles rather useful. When combined with the sbNormal style, these styles will make the scrollbar automatically align themselves. The only condition of this is that you make the component size the area that you wish to have the scrollbar contained in. For example, if you want the scrollbar to fit inside a window, you might assign one of these styles, and then call this function: Scrollbar.SetPos(0,0, Window.CWidth(), Window.CHeight());. Effectively this retains the scrollbar within the box extending from (0,0) to (Window.CWidth(), Window.CHeight()). SBS_BOTTOMALIGN
SBS_LEFTALIGN
SBS_RIGHTALIGN
SBS_TOPALIGN
sbHorizontal
sbVertical
These styles change the orientation of the scrollbar. You will most likely need to specify one of these to make the scrollbar go a certain way. SBS_HORZ
SBS_VERT
sbSizeGripper This little style adds a 'Size Gripper' to the end of the scrollbar(s). If you do include this style, you'll see a little angled thing at the end of the scrollbar(s). Open NotePad and look in the bottom right hand corner - this is a Size Gripper. You can use the next two styles to change the position of this gripper. This gripper really only applies when you have two scrollbars. SBS_SIZEGRIP
sbSizeGripTL
sbSizeGripBR
These two styles set where the size gripper (as enabled and explained by the above style) is. The first style (with the TL postfix) refers to the Top Left-hand corner. The second style (with the BR postfix) refers to the Bottom Right-hand corner. SBS_SIZEBOXTOPLEFTALIGN
SBS_SIZEBOXBOTTOMRIGHTALIGN

Methods


Prototype Description

void EnableArrows(void);
void DisableArrows(void);
These functions enable or disable the arrows on either end of the scrollbar. It is a very effective way of stopping the user scrolling with the buttons - should you wish to do this.
void DisableTopLeftArrow(void);
void DisableBottomRightArrow(void);
These two functions are an effective way to disable specific arrows. With the first function, you can disable either the top or the left arrow, depending on the orientation of your scrollbar. With the second function, you can disable the bottom or right arrow, again, depending on the orientation of your scrollbar.
int GetPosition(void);
void SetPosition(int Pos);
These functions either return or set the position of the slider on the scrollbar. Using the next function, you can set the range, and make this result meaningful. The position is merely an integer, between 0 and 32,768 (depending on the range that you set).
void SetRange(int Min, int Max); This function sets the range of numbers that the scrollbar uses. Let's say that I set the range to be 10 to 100. Now, if the scrollbar slider is fully at the top or left, the position will be 10. However, if the scrollbar slider is fully at the bottom or right, the position will be 100.
int GetRangeMin(void);
int GetRangeMax(void);
These functions return the range of the scrollbar as it is currently. I think the default range is 0 to 100 - but set the range to serve your needs. You can get whatever range you set by calling these functions.
void SetThumbSize(int Size); You may have noticed on some scrollbars that the slider gets smaller and bigger depending on how much there is to scroll through. However, you also might have noticed that the Scrollbar window class does not automatically do this for you. You'll have to do the math yourself and set it manually. However, don't be to concerned - because Windows does do some of the work. The value that you specify to this function is actually the 'size' of a page. Say for example that you have 10 screenfuls of text. Now you created a scrollbar with a range of 1 to 10 to select what page to display. 1 is the size of page - and you pass this along to this function. Windows then decides how long the slider needs to be, and draws the appropriate scrollbar (one tenth of the scrollbar). Here is another example: say you loaded an image and displayed it on the screen. However, your screens resolution was 800x600 and the image was 1024x768. Therefore, you can use scrollbars. In this case, you would set the range of the horizontal scrollbar to 1 to 1024. Then you would set the page size (with this function) to 800.

Events

Please note that the events listed here are done in pairs; one as a property, and the other as a function. The property is assigned a function name, ie. Object.OnClick = &FunctionName, whilst the function is called to verify that an event has occured. Please see the chapter on event handling for information on how to use these correctly.


Prototype Description Sent under

void (*OnScroll)(fSCROLLBAR* Sender, int Message, int Position); This event occurs when the scrollbar has been scrolled. Position is the final position of the scrollbar. This event occurs repeatedly as anything scrollbar-related happens. Message is one of the following values (taken from the Win32 SDK reference manual):
  • SB_BOTTOM - Scrolls to the lower right.
  • SB_ENDSCROLL - Ends scroll.
  • SB_LINEDOWN - Scrolls one line down.
  • SB_LINEUP - Scrolls one line up.
  • SB_PAGEDOWN - Scrolls one page down.
  • SB_PAGEUP - Scrolls one page up.
  • SB_THUMBPOSITION - Scrolls to the absolute position. The current position is specified by the nPos [Position] parameter.
  • SB_THUMBTRACK - Drags scroll box to the specified position. The current position is specified by the nPos [Position] parameter.
  • SB_TOP - Scrolls to the upper left.
WM_VSCROLL and WM_HSCROLL sent to parent window
void (*OnPageUp)(fSCROLLBAR* Sender, int Position);
void (*OnPageDown)(fSCROLLBAR* Sender, int Position);
These events occurs when the user did a page up or page down on the scrollbar. This can be achieved by clicking above and below the actual slider, which causes the scrollbar to raise or lower one page. Position is the final resting position. WM_VSCROLL and WM_HSCROLL sent to parent window, then checked LOWORD(wParam).
void (*OnLineUp)(fSCROLLBAR* Sender, int Position);
void (*OnLineDown)(fSCROLLBAR* Sender, int Position);
These events occur when the user just moved the scrollbar a little bit - one line's worth. Generally this is obtained by clicking either of the arrows on the scrollbar. Position is the final position after the move. WM_HSCROLL and WM_VSCROLL sent to parent window, then checked LOWORD(wParam).
void (*OnThumbTrack)(fSCROLLBAR* Sender, int Position);
void (*OnThumbTrackEnd)(fSCROLLBAR* Sender, int Position);
The first event occurs repeatedly as the user grabs the slider and moves it around. The second event occurs when the user lets go of the slider. Both events give the current Position of the slider. WM_HSCROLL and WM_VSCROLL sent to parent window, then checked LOWORD(wParam).

Sample Code

The following snippet gives a basic idea of how to use this component.


//Create a scrollbar...
fSCROLLBAR ScrollBar;
ScrollBar.CreateWin(Window.GetHandle(), "Scrollbar", SCROLLBAR_ID,
                    sbUsual, sbNormal | sbVerical | sbAlignRight);

//Make it sit on the far right of the window...
//(We've already applied the sbAlignRight style, so
// all we have to do is set the area for it to be
// aligned in).
ScrollBar.SetAll(0,0, Window.CWidth(), Window.CHeight());

//Now set the range...
ScrollBar.SetRange(10, 100);

//How to set the thumb size:
//determine how much is a 'page' of information. ie. How much
//can you fit in one visible area that is to be scrolled?
//Lets say you display an image full screen. Your display resolution
//is 800x600, and the image is 1024x768. You add scrollbars to the
//sides. Ignoring the width of the scrollbars, you would do this:
//(only the horizontal scrollbar settings shown)
ScrollBar.SetRange(1, 1024);
ScrollBar.SetThumbSize(800); //As much as you can fit on screen.

//That's about it! Enjoy!

Back to indexThe FreeFoote Foundation Classes Documentation