News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Scroll Bar

Started by msmith, February 05, 2006, 03:43:25 AM

Previous topic - Next topic

msmith

If I create a scroll bar in a window, it looks fine, but when I try to move the slider, it "springs" back.

What is required to prevent this? I want it to behave like the slider on a trackbar.

Ratch

msmith,

Quote
What is required to prevent this? I want it to behave like the slider on a trackbar.

     You have to process the WM_VSCROLL message.  This involves calling SetScrollPos,  InvalidateRect, and processing the subsequent WM_PAINT message.

The following is a snipet from Petzold's book.  Obviously, you are not processing the scroll bar messages and updating the position of the "thumb".   Ratch

Quote
When you use scroll bars within your program, you share responsibility with Windows for maintaining the scroll bars and updating the position of the scroll bar thumb. These are Windows' responsibilities for scroll bars:


Handle all processing of mouse messages to the scroll bar.

Provide a reverse-video "flash" when the user clicks the scroll bar.

Move the thumb as the user drags the thumb within the scroll bar.

Send scroll bar messages to the window procedure of the window containing the scroll bar.


These are the responsibilities of your program:


Initialize the range and position of the scroll bar.

Process the scroll bar messages to the window procedure.

Update the position of the scroll bar thumb.

Change the contents of the client area in response to a change in the scroll bar.


MichaelW

There is a dialog example in \masm32\examples\bcraven\controls\.


eschew obfuscation

msmith

Thank you Ratch abd Michael,

Since I have had the TrackBar (slider) control working for some time, I assumed that the scroll bar would work the same way.

Since the trackbar also has the same hscroll and v scroll events, and requires no spoon-feeding, I assumed theat the scroll bar would not either.

As to an observation that I had made earlier in the evening before I discovered this problem, I did notice the following in MSDN:

SBM_SETPOS
wParam = (WPARAM) nPos;           // new position of scroll box
lParam = (LPARAM) (BOOL) fRedraw; // redraw flag

TBM_SETPOS
wParam = (WPARAM) (BOOL) fPosition;
lParam = (LPARAM) (LONG) lPosition;

Notice that both functions accompilsh much the same thing, but the args are reversed. It is obvious that the two controls were developed by two different teams with little or no coordination or project management oversight. It is no wonder that the behavior of these two very similar controls would also differ, albiet unnecessasarily.

Also, the pages of MSDN concerning scroll bars that I have on my computer (not the latest version) make no mention of the facts that you have pointed out for me.

Thanks again,

Mike