MFC Rich Edit Control 2.0 receiving click event

828 Views Asked by At

I was hoping someone out there would help me with my predicament I ran into. Essentially I have a Checkbox and a RichEditControl next to each other. I want to be able to know when a user has clicked on my RichEditControl so i can send a message to my checkbox to flag it on and off.

At first i tried to overlay my checkbox with empty text to act as a "blank" background for my RichEditControl so i wouldn't have to worry about sending messages left and right. No matter what i tried the "blank" background would overlap the RichEditControl text and leave it completely blank.

I searched on here for some help and i found this which is exactly what I ran into. I understand what he is saying but don't have the knowledge to implement what they said.

Right now I'm playing around with EN_LINK to attempt to capture a message so i can tell my checkbox to flag itself.

BEGIN_MESSAGE_MAP(TempInit, CDialog)
ON_NOTIFY(EN_LINK, IDC_TempInitMsg, &TempInit::OnEnLinkTempinitmsg)
END_MESSAGE_MAP()

void TempInit::OnEnLinkTempinitmsg(NMHDR *pNMHDR, LRESULT *pResult)
{
ENLINK *pEnLink = reinterpret_cast<ENLINK *>(pNMHDR);
// TODO: Add your control notification handler code here
    // TODO: Add your control notification handler code here
    radioClicked = !radioClicked;
    if (radioClicked == true)
    {
        GetParent()->SendMessage(WM_MYRADIOCLICKED, CHECKENABLED, 0);
    }
    else
    {
        GetParent()->SendMessage(WM_MYRADIOCLICKED, CHECKDISABLED, 0);
    }
}
*pResult = 0;
}

I'm sorry in advance if this is totally the wrong way to go about this. I've been googling for a few hours and have come empty handed. If anyone has any other method please help me if possible. I can post more code if what i have above isn't enough.

2

There are 2 best solutions below

1
On

Steven,

One way to go about this would be to handle the EN_MSGFILTER notification from the rich edit control. I can't provide you any code to show you how to do this off hand but here's the documentation for the Notification messages from that the Rich edit control generates. Simply handle it the same way your doing with your radio button.

0
On

This will check the check box when the Rich Edit Ctrl has the focus and untick it when it losses the focus.

BEGIN_MESSAGE_MAP(TempInit, CDialogEx)
  ON_EN_SETFOCUS(IDC_RICHEDIT21, &TempInit::OnEnSetfocusRichedit21)
  ON_EN_KILLFOCUS(IDC_RICHEDIT21, &TempInit::OnEnKillfocusRichedit21)
END_MESSAGE_MAP()

void CMFCApplication1Dlg::OnEnSetfocusRichedit21()
{
  CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK1);
  pCheckBox->SetCheck(1);
}

void CMFCApplication1Dlg::OnEnKillfocusRichedit21()
{
  CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK1);
  pCheckBox->SetCheck(0);
}