Well, I actually did think that it was doing its job, but I was unsure of
how to not make it pop up a second message box. Apparently though from what
you have said, I cannot without subclassing it. Thanks for the info and I
will give that a try.
Z.K.
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
Yep. That's what is supposed to happen. "Clearing" the data is a
"change", so of course
it will pop up a message box.
First, you should not be popping up message boxes in EN_CHANGE handlers.
This leads to
all kinds of confusion. If you need a MessageBox, do a PostMessage to
cause it to happen
at another time. During the EN_CHANGE, you are in an intermediate state
and popping up a
messagebox could quite possibly have serious consequences.
When I need to change the contents of a CEdit without generating a
notification, I do it
as follows:
I subclass the edit control, making CNoNotifyEdit
I add a reflected =EN_CHANGE handler to it.
I hand-edit the prototype to change it from void to BOOL, and likewise in
the
implementation
I change the macro from ON_EN_CHANGE_REFLECT to ON_EN_CHANGE_REFLECT_EX.
Initialize the notify BOOL in the constructor...
CNoNotifyEdit::CNoNotifyEdit()
{
notify = TRUE;
}
The changed message map entry would be
ON_CONTROL_REFLECT_EX(EN_CHANGE, OnChange)
Then add the method that suppresses the notification
void CNoNotifyEdit::SetWindowTextNoNotify(LPCTSTR s)
{
CString old;
CEdit::GetWindowText(old);
if(old == s)
return; // do nothing, already set
BOOL previous = notify;
notify = FALSE;
CEdit::SetWindowText(s);
notify = previous;
}
The reflected handler is trivial
BOOL CNoNotifyEdit::OnChange()
{
return !notify;
}
joe
On Thu, 17 Aug 2006 11:12:28 -0700, "Z.K." <nospam@nospam.net> wrote:
If I use OnEnChangeEditData and popup a messagebox, it works okay, but
when
I also try to clear the datat that was entered in the editbox, I get
endless
messageboxes. How do I prevent this and why does this happen?
Z.K.
void CTravelerView::OnEnChangeEditData()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the
CFormView::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
MessageBox("The File to be printed has not been selected,\n Select a file
first!", "File Not Selected", MB_ICONSTOP | MB_OK);
m_Edit_Data.SetWindowText("");
}
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm