1

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()
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Michal Hadraba
  • 347
  • 1
  • 11
  • The [`EN_CHANGE`](https://learn.microsoft.com/en-us/windows/win32/controls/en-change) notification is sent to the parent of the control. Are you using [message reflection](https://learn.microsoft.com/en-us/cpp/mfc/handling-reflected-messages)? – IInspectable Jan 14 '22 at 10:37
  • Tell us more about the `OnEnChange` "hook procedure". – Jabberwocky Jan 14 '22 at 11:08
  • I agree with IInspectable. `EN_CHANGE` is sent to the Edit's parent window to begin with, and is then being reflected to the Edit for processing. So, simply don't do the reflection. Or, if you must let the Edit process the reflected message, then you should send a *custom* message back to the parent window, don't reuse `EN_CHANGE` (which is likely to just confuse the parent). Otherwise, just have the parent process `WM_NOTIFY` *before* reflecting `EN_CHANGE` to the Edit. – Remy Lebeau Jan 15 '22 at 02:46

1 Answers1

2

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
Michal Hadraba
  • 347
  • 1
  • 11