Problem
I was using EditControl window to dump some logging/trace messages line by line and found out that a simple routine involving:
SendDlgItemMessage(hwndDlg,IDC_SOMEEDITCONTROL,
EM_REPLACESEL,0,(long)lpszTextBuffer);
works only if you don't reposition the caret in EditControl window (which inadvertantly happens when you scroll back and forth to check on previous messages...). So, if you by accident repositioned the caret, the next text dump will disrupt existing line and produce undesirable effect of garbled data...
A Solution
A simple workaraound may help -- the following "duo" does the trick:
SendDlgItemMessage(hwndDlg,IDC_SOMEEDITCONTROL, EM_SETSEL, 0, -1);
SendDlgItemMessage(hwndDlg,IDC_SOMEEDITCONTROL, EM_SETSEL, -1, -1);
This will position a runaway caret to the end of the text in EditControl..., so that the next call to:
SendDlgItemMessage(hwndDlg,IDC_SOMEEDITCONTROL,
EM_REPLACESEL,0,(long)lpszTextBuffer);
will append a new line to the bottom of the existing body of text... ;-)