void CMyDlg::OnIndex()
{
// TODO: Add your control notification handler code here
CString str;
m_FileText.GetWindowText(str);
int nfirst,nend;
m_FileText.GetSel(nfirst,nend);
// CString str1=str.Mid(nfirst,nend-nfirst);
if (nfirst == nend)
{
MessageBox("No Select!");
}
else
{
str.Insert(nfirst,"<<");
str.Insert(nend+2,">>");
m_FileText.SetWindowText(str); //
m_FileText.SetFocus(); // 返回焦点
m_FileText.SetSel(nfirst,nend+4); // 重设光标
}
}
SetSel()需要与SetFocus()配合使用。如果不配合使用一般不会看到文本选择,因为焦点不在文本框内。
MFC重设光标位置
最新推荐文章于 2022-05-19 10:57:39 发布