文本更改后刷新 CComboBoxEx 项目

Refresh a CComboBoxEx item after the text has been changed

我有这个代码:

void CChristianLifeMinistryEditorDlg::UpdateDatesCombo()
{
    for (int iDate = 0; iDate < m_cbDates.GetCount(); iDate++)
    {
        auto *pEntry = (CChristianLifeMinistryEntry*)m_cbDates.GetItemDataPtr(iDate);
        if (pEntry != nullptr)
        {
            COMBOBOXEXITEM cmbItem;
            CString strDateOriginal = _T("");
            CString strDateNew = FormatWeekOfMeetingText(pEntry->GetMeetingDate());

            // Get the existing item from the combo
            cmbItem.mask = CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_TEXT | CBEIF_LPARAM;
            cmbItem.iItem = iDate;
            cmbItem.pszText = strDateOriginal.GetBuffer(_MAX_PATH);
            cmbItem.cchTextMax = _MAX_PATH;
            m_cbDates.GetItem(&cmbItem);
            strDateOriginal.ReleaseBuffer();

            // Update the text
            strDateNew = FormatWeekOfMeetingText(pEntry->GetMeetingDate());
            cmbItem.pszText = strDateNew.GetBuffer(_MAX_PATH);
            m_cbDates.SetItem(&cmbItem);
            strDateNew.ReleaseBuffer();
        }
    }
}

它工作正常并正确地将下拉列表从一种语言更改为另一种语言。

但是,直到我将鼠标悬停在控件上时,组合中的现有值才会更新。

我已经试过了m_cbDates.UpdateWindow,没什么区别。

我看到了这个 question 但我的问题与文本有关,与图像无关。

如何让 CComboBoxEx 强制显示更新后的文本值?

要更新控件,您必须调用:

m_cbDates.RedrawWindow (NULL, NULL, 
    RDW_INVALIDATE | RDW_FRAME | 
    RDW_UPDATENOW | RDW_ALLCHILDREN);

详细了解 RedrawWindow here