I wish to programatically resize a CComboBoxEx object.
Unfortunately, there are very few posts on this issue and none provide a satisfactory solution.
I should note that my requirement is to resize the entire CComboBoxEx object, much as one would resize a CEdit text box, that is displayed in a dialog bar that resizes with CMainFrame::OnSize. If I don't try to resize the CComboBoxEx window, it works just fine. But all of my attempts to resize it have resulted in it blanking out.
Has anyone encountered this problem and come up with a solution?
The combo box common control object cannot be resized vertically, it can only be resized horizontally. For that you use a simple MoveWindow()-type API. If you need to use a combo box that is resizable on all 2 axis, then you need to either make it yourself (which, I understand, is not quite easy) or use any of the ActiveX-type combo boxes.
To demonstrate the problem that I am having, I have attached an example application.
Notice that the dialog bar resizes just fine, but when I try to use the following code, the ComboBoxEx component fails to work properly, even though it resizes. Note also that this same code, when applied to a CEdit component, works as it should, resizing both the dialog bar and the CEdit component.
void CMainFrame::OnSize(UINT nType, int cx, int cy)
CFrameWnd::OnSize(nType, cx, cy);
CComboBoxEx * pComboBox;
pComboBox = (CComboBoxEx*)m_wndDlgBar1.GetDlgItem(IDC_COMBOBOXEX1);
if(m_wndDlgBar1) // resize the dialog bar comboboxex window if visible
pComboBox->MoveWindow(r.TopLeft().x, r.TopLeft().y, cx-6, r.Height()-3, TRUE);
So, save yourself a step. Also highlighted part above is not going to work. As I told you before, you cannot change the height of the combo box. So replace it with it's real height. To get it call pComboBox->GetWindowRect() before.
(4) I don't think you need to call RecalcLayout() for just resizing your combo box.