Sendmessage from subclassed control (CEDIT) to parent window

295 views Asked by At

I have subclassed a CEdit control (CCheckeEdit).

I need to catch ON_CHANGE for this class and send the message to dialog (catch EN_CHANGE in dialog, too).

In subclassed CCheckeEdit, I have followed hook procedure:

BEGIN_MESSAGE_MAP(CCheckedEdit, CEdit)
    ON_WM_CHAR()
    ON_WM_CTLCOLOR_REFLECT()
    ON_CONTROL_REFLECT(EN_CHANGE, &CCheckedEdit::OnEnChange)
    ON_WM_TIMER()
    ON_WM_NCMOUSEMOVE()
END_MESSAGE_MAP()
//....
//....

void CCheckedEdit::OnEnChange()
{
    Validing();
    int res = ::SendMessage(GetParent()->m_hWnd, WM_COMMAND, (WPARAM)MAKELONG(3, EN_CHANGE), (LPARAM)GetParent()->m_hWnd);
}

and in the dialog I have:

BEGIN_MESSAGE_MAP(CProjMfcDlg, CMjAcDialog)
    ON_EN_CHANGE(IDC_EDIT, &CProjMfcDlg::OnEnChangeEdit)
END_MESSAGE_MAP()

void CProjMfcDlg::OnEnChangeEdit()
{
    CString str;
    GetDlgItemText(str);
    if(str==....)
    // some validating code
    // set some button disable or enable
}

But CProjMfcDlg::OnEnChangeEdit() will not process (I have breakpoint there).

What am I doing wrong?

OnEnChange procedure is whole in question above. Yes, I use a MFC reflection:

BEGIN_MESSAGE_MAP(CCheckedEdit, CEdit)
    ON_WM_CHAR()
    ON_WM_CTLCOLOR_REFLECT()
    ON_CONTROL_REFLECT(EN_CHANGE, &CCheckedEdit::OnEnChange)
    ON_WM_TIMER()
    ON_WM_NCMOUSEMOVE()
END_MESSAGE_MAP()
1

There are 1 answers

0
Michal Hadraba On

I have just solved it.

The correct way is to use ON_CONTROL_REFLEX_EX instead ON_CONTROL_REFLEX.

Then the message is sent first to the control and then, depending of return value from control hook procedure (FALSE), also to the parent window.