tags:

views:

455

answers:

2

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.

A: 

Here is already solved

Vinay
`m_Combo.ModifyStyle(CBS_DROPDOWNLIST, CBS_DROPDOWN);` returns true but has no effect :(
Nick
A: 

Won't it just be enough to set the control's font to the dialog font? That is, after immediately after recreating the control

m_Combo.SetFont(GetFont());

DavidK