1
votes

This is an Windows MFC programming issue. I have a derived CComboBox which implement its own item draw and measurement. I did a little enhancement that the drop down list width is adjustable based on the list content. I use SetDroppedWidth in OnDropDown message handler to do it. After I insert strings and click the combo box, the selected string content seized all static/edit area, and drop down button is missing. I could see the width of the item, which has item ID -1, is changed/reset to the new dropped width in ItemDraw method. I don't think this is the right behavior. I want the new dropped width only take effect on list items, item ID of which is not less than 0. Any idea?

1
try to call SetDroppedWidth after you initialise the combobox items. I think calling it inside the OnDropDown method is not a right placecha
But in this way, the combobox width could only be adjusted once, because the initialization is called only once.Buzz

1 Answers

1
votes

Try to use this.

In your OnDropDown handler Call CComboBox::GetComboBoxInfo. It will return you the pointer of COMBOBOXINFO structure. This structure among the others contains the HWND of the dropdown listbox hwndList. Use MoveWindow() API on this hwndList directly and see if it works

If that does not work, try posting the CB_SETDROPPEDWIDTH message. As you know, SetDroppedWidth is just a wrapper for CB_SETDROPPEDWIDTH message. It is implemented as a SendMessage call. Try this one:

::PostMessage(m_myComboBox.GetSafeHwnd(), CB_SETDROPPEDWIDTH, nWidth, 0);