Creating Windows Scrollbars

Perhaps, I should rephrase my question, as my last attempt went off on a tangent. What is the best, most-up-to-date way of creating and implementing scrollbars in C++? Obviously, the old WS_HSCROLL and WS_VSCROLL are no longer used. However, hours of internet searches have yet to yield a straight answer to this question. Please forgive me if I sound frustrated--I am.
What is the best, most-up-to-date way of creating and implementing scrollbars in C++?


Flat scroll bars behave just like standard scroll bars. The difference is that you can customize their appearance to a greater extent than standard scroll bars.


https://docs.microsoft.com/en-us/windows/win32/controls/flat-scroll-bars
Thanks Malibor. There is just one thing. I found this disturbing note on the documentation page that you suggested:


Flat scroll bars are supported by Comctl32.dll versions 4.71 through 5.82. Comctl32.dll versions 6.00 and later do not support flat scroll bars.


Is there now some newer method?

I have another unrelated question: What is the difference between the macros WS_VSCROLL and SBS_VERT? I have seen both used in the CreateWindow() and CreateWindowEx() functions.

I also found this interesting discussion on the forum:

http://www.cplusplus.com/forum/windows/33601/

From that thread, I was able to find a pdf of Petzold's tutorial on the use of the SCROLLINFO structure. Still, what do the ScrollWindow() and ScrollWindowEx() functions do? In both code examples, one of those functions is called in both WM_HSCROLL and WM_VSCROLL cases. Yet, the WM_PAINT case is still having to repaint the entire client area.
Programming Windows, 5th Edition code for creating child window scroll bar controls, updated to not barf with modern versions of Windows:
https://github.com/recombinant/petzold-pw5e/blob/master/Chapter%2009%20Child%20Window%20Controls/Colors1/Colors1.c

Petzold may be old, but the Win32 SDK still works from 1998 with a bit of tweaking.
What is the difference between the macros WS_VSCROLL and SBS_VERT?


WS_VSCROLL is window style while SBS_VERT is common control style.

window style mans that when you create a window such as top level window, with this flag you specify that the window has scrollbar, whose messages you then handle in window procedure.

common control style is a flag when you subclass or superclass common control (scrollbar) in this case, where the SBS_VERT tells that the scroll bar common control your are creating is vertical scroll bar.

Flat scroll bars are supported by Comctl32.dll versions 4.71 through 5.82. Comctl32.dll versions 6.00 and later do not support flat scroll bars.

I didn't know that honestly, probably because I never used flat scrollbar, but if it's not supported for Comctl version 6 then that means IMO creating custom scrollbar or subclassin common control scrollbar is more modern way to do it. at the expense of being harder to do implement it I guess.

what do the ScrollWindow() and ScrollWindowEx() functions do?

These are used to scroll window client area while the user drags the scrollbar.
Petzhold has good example on how to do it.

the WM_PAINT case is still having to repaint the entire client area.

WM_PAINT is better passed to default procedure unless you want to paint the scrollbard yourself ex. to apply custom uxtheme/visual styles.

It's not that hard to do, you only need to know which API's to use for drawing control frames (with or without styles).

visual styles are documented on MSDN as bad as some non public API's, I spent weeks to "unlock" how to use it.
Thanks Furry Guy and Malibor. I have found a PDF version of Petzold's entire Fifth Edition, which I have downloaded for reference. I have found the Fourth Edition to be a good starting point, as the explanations are much more in-depth. I could then browse the same section in the fifth edition, to learn about the updates.

For the moment, I'm going to use SCROLLINFO, until I learn more about child windows and subclasses.


Visual styles are documented on MSDN as bad as some non public API's, I spent weeks to "unlock" how to use it.


Now, I don't feel so bad.

It took a bit of parsing of Petzold's code, to see what he was doing. In scrolling, he is limiting his painting to just the newly exposed area. That was not obvious at first glance.

Which, brings up an interesting question about scrolling images. I have noticed in many code examples, that an image is scrolled, simply by changing its origin point. This causes the entire window to refresh. I realize that this greatly simplifies the code. But, is this really the most efficient way to do this?
Topic archived. No new replies allowed.