如何在编辑控件中插入字符串 [英] How to insert string in edit control

查看:79
本文介绍了如何在编辑控件中插入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在运行时在编辑控件中添加字符串,我尝试了不同的方法和策略,但它不会插入或插入但不会在编辑控件中显示!!!

如何制作这个!请给我解决方案。

提前致谢!!

I''m going to add string at runtime in edit control,I''ve tried with different method and strategies but it won''t inserted or if inserted but not displayed in edit control!!!
How to make this!please give me solution.
Thanks in advance!!

推荐答案

通过设置插入来执行使用 SetSel()将位置索引作为起点和终点传递,并用调用 ReplaceSel()。要附加文本,请将-1作为位置索引传递。要设置完整文本(全部替换),请使用 SetWindowText()



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().

// Insert text at specified position using a CEdit derived class
void CMyEdit::InsertText(int nPos, LPCTSTR lpszText)
{
    SetSel(nPos, nPos);
    ReplaceSel(lpszText);
}

// Insert text at specified position of a CEdit control that is a member of a dialog
void CMyDialog::InsertEditText(int nPos, LPCTSTR lpszText)
{
    m_edit.SetSel(nPos, nPos);
    m_edit.ReplaceSel(lpszText);
}

// Insert text at specified position of a CEdit inside a dialog using the resource ID
void CMyDialog::InsertText(int nID, int nPos, LPCTSTR lpszText)
{
    CEdit *pEdit = (CEdit *)GetDlgItem(nID);
    pEdit->SetSel(nPos, nPos);
    pEdit->ReplaceSel(lpszText);
}


这篇关于如何在编辑控件中插入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆