When you click on the "dropdown" button of a combobox, the dropped down listbox appears below the combobox, unless there is not enough space below, in which case the listbox appears above.
Now I wonder if there is a possibility to force the lisbox to appear above the combobox, even if there is enough space below.
Illustration
When I click on the combo box, I'd like the "drop down" list box appear always above as on the left screen copy.
Everything is possible, and you don't need to implement the control "from scratch".
First, you can subclass the ListBox part of your ComboBox to get complete control over it, as explained in MSDN. You can create a class, derived from CListBox, using the Class Wizard. You only need to implement
WM_WINPOSITIONCHANGING
handler in it:Here, for simplicity, I am moving the box up by the (heights+30). You can get the height of your ComboBox instead of my
30
.Then you declare a member variable in your dialog class:
and subclass it like that:
Note that I am calling
m_listbox.MoveWindow(r)
there; it is needed because firstWM_CONTROLCOLOR
message for that list box comes after it is positioned, so the very first time it would drop down instead of up.Disclaimer: this is not a very clean solution, as, if you have windows animation enabled, you'd see that the list unrolls from top to bottom.
Alternatively, you should be able to "fool" the combobox that it is too close to the bottom of the screen; then it will drop up by itself. I leave it as an exercise for the readers :)
This would be relatively easy except when combo box has "slide open" effect. If you move the dropdown listbox to the top, and the combo slides open from top-to-bottom, it would look odd. So you have to disable the animation or reverse it.
In this function I call
AnimateWindow
inOnWindowPosChanging
, it doesn't seem to cause any problems but I am not a 100% sure about it!Usage:
Also you can use
SetMinVisibleItems
to reduce the listbox height and make sure the dropdown list fits on top.