Windows Scroll Bar
Windows Predefined Controls – Part 27
Volume - Windows User Interface
Forward: In this part of the series, we look at Windows Scroll Bar.
By: Chrysanthus Date Published: 30 Aug 2012
Introduction
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Why a Scroll Bar
The size of the computer screen is limited (in width and height). The size of a window, smaller than the computer screen is more limited. You can have a document or an image that is more than the size of the client area of a window; yet you want the user to be able to see the whole document or images when it is displayed in the client window. To achieve this, you need scroll bar for the window.
What is a scroll bar?
A scroll bar is a vertical or horizontal bar in a window or control. A scroll bar is made up of a shaded shaft with an arrow button at each end and a scroll box between the two arrow buttons. This scroll box is sometimes called a thumb. A scroll bar represents the overall height (going downward) or width of a data in a window's client area; the scroll box indicates the portion of the data that is visible in the client area. You must have seen scroll bars as you use windows applications. You can have a veridical scroll bar and/or a horizontal scroll bar in a window.
The position of the scroll box changes whenever the user scrolls data to display different portions. The operating system also adjusts the size of a scroll bar's scroll box so that it indicates what portion of the entire data is currently visible in the window. If most of the data is visible, the scroll box occupies most of the scroll bar shaft. On the other hand, if only a small portion of the object is visible, the scroll box occupies a small part of the scroll bar shaft.
The user can scroll the content in the window or control by clicking one of the arrow buttons. He can also scroll the content by clicking the area in the shaded scroll bar shaft, or by dragging the scroll box.
If the user clicks an arrow button, the application or operating system would scroll the content by one unit (typically a single line vertically or column horizontally). When the user clicks the shaded areas, the application scrolls the content by one window. The amount of scrolling that occurs when the user drags the scroll box depends on the distance the user drags the scroll box and on the scrolling range of the scroll bar.
You can move the scroll box from one end of the scroll bar to the other. That distance is the scrolling range. It has a range of integers associated with it say from 0 to 100. The scroll box can have a position anywhere within that range.
Parts of a Scroll Bar
You now know that we can have a vertical scroll bar and a horizontal scroll bar. We know that a scroll bar has two arrow buttons at its ends and a scroll box.
For a vertical scroll bar, the arrow button at the top can be called the lineup button. The shaded area between the lineup button and the scroll box can be called the pageup button. The arrow button at the bottom can be called the linedown button. The shaded area between the linedown button and the scroll box can be called the pagedown button.
For a horizontal scroll bar, the arrow button at the left can be called the lineleft button. The shaded area between the lineleft button and the scroll box can be called the pageleft button. The arrow button at the right can be called the lineright button. The shaded area between the lineright button and the scroll box can be called the pageright button.
Creating a Scroll Box
This is one of the easiest things to create in windows. So far we have been using the CreateWindowEx function to create windows and controls. This function has the dwStyle argument whose value are the styles for the window or control. To create a vertical scroll bar, just add the windows style, WS_HSCROLL to the dwStyle argument. Also, to create a horizontal scroll bar, just add the windows style, WS_VSCROLL to the dwStyle argument.
When you create a scroll bar this way, we say you have created a standard scroll bar. A standard scroll bar is located in the nonclient area of a window. Alternatively, you can create a scroll bar as a control. That comes with some advantages; however, I will not discuss scroll bars as controls in this series.
That is it for this part of the series. We stop here and continue in the next part.
Chrys
Related Courses
C++ CourseRelational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem