The problem is that if the text is updated within the code then OnChangeEditName() will immediately get another 'on change' call so you need to ignor the next 'on change' when the text is changed, otherwise it will create an infinite loop.
Something like this seems to work and also moves the cursor to the end of the text.
Code:
bool FormatDate(char *Buffer)
{
// DD/MM/YY
if( /*date buffer needs modifing then*/ )
{
//modifiy the date string etc...
return 1
}
return 0;
}
void CEditSampleDlg::OnChangeEditName()
{
static bool IgnorNextChange = 0;
char Buffer[50];
m_EditSearchUpdate.GetWindowText( Buffer, 50 );
if( !IgnorNextChange && FormatDate(Buffer) )
{
IgnorNextChange = 1;
m_EditSearchUpdate.SetWindowText("");
m_EditSearchUpdate.ReplaceSel(Buffer);
}
IgnorNextChange = 0;
}