Info about Scrollbars..

Posted on 1998-10-28
Last Modified: 2008-03-17
A window can have scrollbars if the appropriate style bits are set.  As it is scrolled, WM_VSCROLL and WM_HSCROLL messages are sent to the window.  If I look at it with Spy++, I don't see any child windows (the scrollbars)  I am making a fully user drawn window and would like to have non-standard looking scrollbars without the hastle of creating them from scratch.  Spy++ lists these additional Scrollbar messages..

I suppose that I thought the scrollbars would be child windows that get these messages and would in turn send the WM_VSCROLL messages to it's parent.  I can't seem to get Spy++ to log a single SMB_ message.

So what's the deal?  I would ideally like to get device contexts to the different components of the scrollbar such as the thumb, slide and buttons.  That way, I could draw them to match my form but keep the normal functionality.

Is this possible?
Question by:GaryC
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
LVL 22

Expert Comment

ID: 1176406
There are two "types" of scroll bars.  There are "window scrollbars" which as you now know are not child windows.  They are part of the window's non-client area.  The other type are "scrollbar controls" these are child windows--just like other controls.

LVL 22

Expert Comment

ID: 1176407
To do your own scrollbars, you have two choices.  

You can continue with the windows design and not make your non-standard scroll bars child windows.  To do this you would paint them when you pain the non-client area of the window, or when scrolling messages occur.  

Or you can go with a bit "structured" design and make the scroll bars child windows.  (Which will be drawn when they get WM_PAINT messages).  If you go this route however, you will need to handle "communication" between the scroll bars controls and the window they belong to.  That is when they are scrolled they will need to send scroll messages to their parent..  (Also when the parent's information changes in size it needs to notify them.)  (one dissadvatage to this approach is that the scrollbars will be located in the client area--child windows cant be in the non-client area--this may make positioning/drawing calculations a little tougher.

Let me know if you have questions.

Author Comment

ID: 1176408
I have no other option to select (outside of accepting) then reject and that word seems so harsh.  I appreciate the input.

Yep, I know about scrollbar controls.  I'm dealing with the scrollbars that are "attached" to a window as definded in it's style bits.  I may or maynot be writing the code to link a scrollbar to a view.  I want my app to be able to subclass any of my forms however they were made so that I don't have to recreate the wheel for all the possible forms.  In theory, I would be able to hook into the message loop and draw what I want.  It's easy to do with the non-client area but i'm baffled with the scrollbars.  When I redraw, how do I know where to draw the thumb?  What processes the hit test to know what part of the scroll bar was hit?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 22

Accepted Solution

nietod earned 200 total points
ID: 1176409
You don;t have to reject an answer, if you just need more information.  Leave the grading boxes empty and post a comment asking for more info.

>>I'm dealing with the scrollbars that are "attached" to a
>> window as definded in it's style bits.
My point is that since you are doing it yourself, you can do it either way.  You might find adding controls easier.  Maybe not.

>> how do I know where to draw the thumb?
If you are usign window scrollbars use GetScrollInfo() and specify the window handle of the window (not the scrollbar control--as there is none) and also specufy SB_VERT or SB_HORS in the fnBar parameter to indicate which scroll bar you are interested in
LVL 22

Expert Comment

ID: 1176410
>> What processes the hit test to know what part of the scroll bar was hit?

I'm not sure what you mean.  You will process the WM_HSCROLL AND WM_VSCROLL to scroll your client are to a new position.  I.e. you will do scroll specific information in those message handles.  Ussually you will calculate and record the new position and then just invalidate the client area so that the next WM_PAINT draws things in the new scroll position.

LVL 22

Expert Comment

ID: 1176411
What is happening with this queston?  Do you still need help?
LVL 22

Expert Comment

ID: 1176412
Still there?  Still need help?

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question