Inserting is performed by setting the position with
SetSel()
passing the position index as start and end point and replacing the (empty) selection with the text calling
ReplaceSel()
. To append text, pass -1 as position index. To set the complete text (replace all), use
SetWindowText()
.
void CMyEdit::InsertText(int nPos, LPCTSTR lpszText)
{
SetSel(nPos, nPos);
ReplaceSel(lpszText);
}
void CMyDialog::InsertEditText(int nPos, LPCTSTR lpszText)
{
m_edit.SetSel(nPos, nPos);
m_edit.ReplaceSel(lpszText);
}
void CMyDialog::InsertText(int nID, int nPos, LPCTSTR lpszText)
{
CEdit *pEdit = (CEdit *)GetDlgItem(nID);
pEdit->SetSel(nPos, nPos);
pEdit->ReplaceSel(lpszText);
}