0
votes

i have a rich edit box in one of my dialog of MFC dialog based app. it can only have numeric values. Now what i am trying to do is dont allow user to enter a value greater then 4567899. if user is entering numbers in the the rich edit box and by pressing the number key will make the value already enterd in text box greater then 4567899 then just make the app behave like no key is pressed or just ignore that key press.

I did some research and found that this can be done by EN_MSGFILTER event but i m not sure about that.

so this is the function

    void CMyDialog::OnMsgfilterObjectid(NMHDR* pNMHDR, LRESULT* pResult)  
    {
char tempID[10];
MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
// TODO: The control will not send this notification unless you override the
// CDialog::OnInitDialog() function to send the EM_SETEVENTMASK message
// to the control with either the ENM_KEYEVENTS or ENM_MOUSEEVENTS flag 
// ORed into the lParam mask.

// TODO: Add your control notification handler code here

*pResult = 0;
    if((pMsgFilter->wParam >= 48) || pMsgFilter->wParam<=57) // check if 0-9 is pressed
{ 
     m_objectIDInstance.GetLine(NULL,tempID);  //m_objectIDInstance is a CRichEditCtrl
 tempID[m_objectIDInstance.LineLength()] = '\0';
 if ((atol(tempID) + (pMsgFilter->wParam-48)) > 4567899)
     {
     *pResult=1;
     }
    }
    }

in OnInitDialog() i added following line:

    m_objectIDInstance.SendMessage(EM_SETEVENTMASK, 0, ENM_KEYEVENTS);

Buts its not working so please if somebody can help or can suggest a different way to do what i am trying to implement.

Thanks

1

1 Answers

0
votes

You seem to be sending the message to the dialog. It has to be sent to the edit control.

m_objectIDInstance.SendMessage(...)