Question

I have a dialog box with several comboboxes in it as a member variables. The control wizard lets me create handlers for the comboboxes for the CBN_KILLFOCUS message. For example, one such handler is automatically called

void MyDlg::OnKillfocusMyCombo()

My expectation is that this handler would be called just as soon as I tab out of it. But it doesn't get called.

Was it helpful?

Solution

I ran into the same issue. This is a bug in MFC. (It's over 4 years later and it is still there.) Somehow ON_CBN_KILLFOCUS handler is never called although the Win32 CBN_KILLFOCUS notification itself is broadcast.

To fix this override the WindowProc for the dialog manually (Win32-way):

LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    // TODO: Add your specialized code here and/or call the base class

    //Fix for the bug in MFC
    if(message == WM_COMMAND)
    {
        if(HIWORD(wParam) == CBN_KILLFOCUS &&
            LOWORD(wParam) == Your_ComboBox_ID)
        {
            OnCbnKillfocusComboBox();
        }
    }

    return CDialog::WindowProc(message, wParam, lParam);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top