[MFC] Drawing the scroll bar on owner-drawn combo boxes.

Started by
1 comment, last by uncle_rico 17 years, 7 months ago
Hey guys, I've found this challenge to be a it too complex for me. Here's what I've found out so far. A combo box is actually a combination between an edit control and a list box control. The list box control is of the class ComboLBox. It is not a child of the combo box control. In fact, I have no idea how it is created, but apparently the only way to access it is to check for the WM_CTLCOLORLISTBOX message, and the LParam will contain a handle to it. You can then use the handle to subclass the ComboLBox to any class you want. I want to be able to skin combo boxes, so I searched online and found someone who uses the above technique in order to draw the list box portion. His list box class checks for WM_PAINT messages and then he uses GetClientRect in order to get the rectangular area of the control, and then draws to it. The problem is that he doesn't ever draw the scroll bar, and so if the number of list box items exceeds that which can be displayed with the current list box height, there is no scroll bar there for you to use to reveal the others (actually, it's there, but it's not being drawn; as soon as you click the invisible area where it is supposed to be, it is drawn). I've been trying to research ways to fix this, but it is very hard. I thought that perhaps the ComboLBox class had a CScrollBar member that I could access. I guess that would be too easy. I read through the implementation of of CListBox and all the methods do is send windows messages. It's sort of hard to trace the program flow beyond that unless I study Win32 for a few more weeks or something. I dunno. There doesn't seem to be any direct reference to a scroll bar anywhere in the definition or implementation. Does anyone have any ideas? If I could just somehow get the rects for the scroll bar buttons, the tick, and the bar itself I could probably handle the actual drawing quite easily.
Advertisement
Quote:Original post by uncle_rico
If I could just somehow get the rects for the scroll bar buttons, the tick, and the bar itself I could probably handle the actual drawing quite easily.


that's just it... you can't. the only way i know of to get an owner draw scroll bar in the listbox portion of a combo box is to create a custom combobox control from scratch. this is because the scroll bar in the standard listbox is not actually a window - it is part of the non-client area. it does not send any owner draw notification messages (because it's not a child window). even if they were actual windows, ie. scrollbar controls, you couldn't owner draw them because Windows really doesn't like you messing with their scrollbars (there are no ownerdraw styles or messages even for scrollbar controls).

so my advice to you would be:
1.) stop trying and use standard scollers, as it can't be done with the standard combobox.
2.) write your own combobox.
OH, that bums me out!

Thanks for the info though! :)

This topic is closed to new replies.

Advertisement