Combo Box selection, WM_SETREDRAW and CB_SETCURSEL

Given the combo box initialization code:

for(INT nIndex = 0; nIndex < 3; nIndex++)
    m_ComboBox.AddString(AtlFormatString(_T("Item %d"), nIndex + 1));

How the combo box is going to look like?

Here it goes:

ComboBoxSample01 #1

Combo box won’t repaint window on SetRedraw(TRUE) AKA WM_SETREDRAW. But once you move a mouse pointer over the control, or tab to focus it, the correct selection will be painted, “Item 2”:

ComboBoxSample01 #2

The control ignores the invalidation caused by CB_SETCURSEL message while processing final SetRedraw message. To avoid GUI glitches, for example, a m_ComboBox.Invalidate() or InvalidateRect might be called after SetRedraw(TRUE).

Leave a Reply