I need to switch between the CBS_DROPDOWN and CBS_DROPDOWNLIST styles at runtime. It looks like the only way to do this is to re-create the control.
So I have the following code:
CRect rect;
m_Combo.GetWindowRect(&rect);
m_Combo.DestroyWindow();
m_Combo.Create(CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP | WS_VISIBLE, rect, this, IDC_MYCOMBO);
But all that happens is the combo disappears. What am I missing?
EDIT:
Using ModifyStyle
is not an option because this style cannot be changed at runtime. The control must be recreated.
EDIT 2:
Okay, so I was in screen coordinates instead of dialog coordinates.
CRect rect;
m_Combo.GetWindowRect(&rect);
ScreenToClient(&rect); // SUPER IMPORTANT :)
m_Combo.DestroyWindow();
m_Combo.Create(CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP | WS_VISIBLE, rect, this, IDC_MYCOMBO);
But now, the position is right but the font does not match the dialog font.