Avatar of Kelaros
Kelaros
Flag for United States of America asked on

How to ownerdraw the internal scrollbar of a ListBox in C++?

I am using C++ with MS Visual Studio and the Windows API, not using MFC.

My problem is this:

I have a ListBox control with the WS_VSCROLL style and the LBS_OWNERDRAWVARIABLE style set -- I want to draw the internal scrollbar, the one created from WS_VSCROLL, myself, but I cannot figure out how to stop the default scrollbar from drawing (without removing the WS_VSCROLL style, which I want there for its functionality).

I can ownerdraw my custom scrollbar over top of the internal one, and this works fine most of the time, except when I am clicking and dragging the internal scrollbar - then the default one draws again.  Ideally what I really want to do is catch the message or function that draws the internal scrollbar, and handle all the drawing myself.

I have found all sorts of kludges online involving creating frame windows or drawing other controls over top of the internal one -- that is not what I want to do.  I want to do it in typical ownerdraw fashion, where I catch the functionality that draws the scrollbar and handle it myself instead of letting it draw.  Is there a way to do this?  

If not, does anyone have a good recommendation as to how to do this in a way that is relatively elegant?

Thanks!
Game ProgrammingC++Visual C++.NET

Avatar of undefined
Last Comment
jgordos

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
itsmeandnobodyelse

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jgordos

Back in the day, you would subclass the window (all windows controls are windows, not just the window you normally think of as the window).

You're responsible for handling all of the WM_PAINT messages, so you can draw whatever you'd like.  Same goes for all the other messages that the window would normally process.

Check out

http://msdn.microsoft.com/en-us/library/ms997565.aspx
http://msdn.microsoft.com/en-us/library/ms997557.aspx

-john

Kelaros

ASKER
The internal scrollbar is actually not a window, it has no handle.  Right now what I have is something similar to what itsmeandnobodyelse said:  I have a child custom scrollbar window that uses my subclassed listbox as a parent, and I conduct all the scrolling myself.  I really didn't want to do it this way but apparently the only way to actually control the internal scrollbar drawing is by hooking the API calls (since the internal scrollbar calls the API directly and does not use the message pump).  I really didn't want to bother with that so for now I just have my child scrollbar which is working ok... seems ridiculous that MS didn't put in a way to custom draw the internal scrollbar.  How odd.  But if anyone DOES know an easier way to do it, please let me know!!
SOLUTION
jgordos

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy