100分,up 有分

pdwling 2002-10-11 05:11:22
用CEdit 如何得到所选择的内容(GetSel),进行处理,之后把选择的内容清除
...全文
64 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsuny 2002-10-11
  • 打赏
  • 举报
回复
up
viscky 2002-10-11
  • 打赏
  • 举报
回复
Up
bager 2002-10-11
  • 打赏
  • 举报
回复
//我已经在VC6.0下调试通过,运行正常。
//请按我的做法试一下,祝成功!
//CEdit m_edit;
CString strTemp,strShow;
int nStartChar, nEndChar;

m_edit.GetSel(nStartChar, nEndChar );
m_edit.GetWindowText(strTemp);
strShow = strTemp.Mid(nStartChar,nEndChar-nStartChar);
AfxMessageBox(strShow);

m_edit.Clear();//删除所选择的内容
//Deletes (clears) the current selection (if any)
//in the edit control.
xlwz 2002-10-11
  • 打赏
  • 举报
回复
Up
coal2000 2002-10-11
  • 打赏
  • 举报
回复
up
superwxh 2002-10-11
  • 打赏
  • 举报
回复
up
eehinjor 2002-10-11
  • 打赏
  • 举报
回复
下面三步:
getcursel
getseltext

setwindowText("");
kwiner 2002-10-11
  • 打赏
  • 举报
回复
这一招试试

this->GetDlgItem(IDC_EDIT)->SetWindowText("");
lfm0214 2002-10-11
  • 打赏
  • 举报
回复
up
wooden7blue 2002-10-11
  • 打赏
  • 举报
回复
帮你up
begar 2002-10-11
  • 打赏
  • 举报
回复
帮你up
用户 昵称 2002-10-11
  • 打赏
  • 举报
回复
CEdit::ReplaceSel
把选择的清除
whydoyoucare 2002-10-11
  • 打赏
  • 举报
回复
同意 cadinfo(无语清风)
cadinfo 2002-10-11
  • 打赏
  • 举报
回复
m_edit.SetSel(-1,0);
m_edit.Clear();
supernets 2002-10-11
  • 打赏
  • 举报
回复
up
everandforever 2002-10-11
  • 打赏
  • 举报
回复
int b,e;
pEdit->GetSel( b, e);

HLOCAL h = pEdit->GetHandle();
LPCTSTR lpszText = (LPCTSTR) ::LocalLock(h);

memcpy( dstbuf, lpszText+b, e-b);//把所选内容复制到dstbuf

::LocalUnlock(h);
_____________

把选择的内容清除:

REPLACESEL("");
everandforever 2002-10-11
  • 打赏
  • 举报
回复
int b,e;
GetSel( b, e);

HLOCAL h = pmyEdit->GetHandle();
LPCTSTR lpszText = (LPCTSTR) ::LocalLock(h);

memcpy( dstbuf, lpszText+b, e-b);

::LocalUnlock(h);
_____________

SETSEL(0,-1);
REPLACESEL("");
fupinger 2002-10-11
  • 打赏
  • 举报
回复
自编求子串函数
substr(char *str1, char *str2, int start, int end)
{
int i=0;
for(int s=start;i<=end-start;i++,s++)
str1[i]=str2[s];
str1[i]='\0';
}

CEdit m_CeditCtrl;
int start,end;

char edit[50];//保存edit中的原始值
m_CeditCtrl.GetWindowText(edit);

m_CeditCtrl.GetSel(&start,&end);//得到所选内容在整个CEdit框中的首位置与未位置

char startstr[50],endstr[50];
char temp[50];
//得到所选中文本之前的edit中的值(备用)
substr(startstr,edit,0,start-1);

//得到所选中文本之后的edit中的值(备用)
substr(endstr,edit,end,strlen(edit));

//得到所选中的edit中的值(备用)
substr(temp,edit,start,end-1);

…………
temp中的值既是你要进行处理的。


…………
如果只是为了处理完后要删掉:
strcat(startstr,endstr);

m_CeditCtrl.SetWindowText(startstr);//现在文本框中是没有选中的文本

如果为了处理完后把它回显:
差不多也就是strcat()后再setWindowText().

一切OK!!


xuying 2002-10-11
  • 打赏
  • 举报
回复
CEdit.GetWindowText()获得所有得内容,保存在一个字符串或CString中
用 GetSel()获得选中的内容的起始和结束位置,就可以进行处理了。
处理后用Clear()清除选中的内容。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧