Reputation: 2018
My question is about combo boxes in Windows MFC applications.
The dropdown part of the combo box contains items composed of a bitmap and a string.
Sometimes, the strings are too long and I have to adjust the width of the dropdown part of the combo box using the CComboBox::SetDroppedWidth()
method.
My problem is that when the combo box is near the right edge of the computer screen, the right part of the dropdown is hidden (see image_1
and image_2
below).
I would like it to behave like in Excel (see image_3
below) meaning I would like the dropdown list to be shifted accordingly so that all its items can be seen without being cropped.
How can this be achieved?
image_1: right part of the dropdown is NOT hidden
image_2: near the computer right edge, the right part of the dropdown is hidden
=================================================================
=================================================================
EDIT 2
Ok. I forgot to mention that m_cbXmodels
is a CComboBoxEx
object. This is why the handles are NULL. I could get the handles via GetComboBoxCtrl()
...
Upvotes: 2
Views: 812
Reputation: 15355
Handle the CBN_DROPDOWN
notification.
Get the handle for the list control with GetComboBoxInfo
.
Now use MoveWindow to adjust the window as needed.
Getting the current screen size is available with MonitorFromWindow
. See rcWork
member in MONITORINFO
. You just need to adjust the left and right coordinates.
EDIT: As you can read in the comments: My Approach with CBN_DROPDOWN is to early Thanks to zett42). It is not possible to resize the combo box list part here.
But it is possible to post a user defined message to the same window and to reposition the window than.
Upvotes: 3