高手帮忙,如何判断输入文本框中选中了那个字符!

fishboyzyf 2008-12-08 03:56:44
我用mFC开发的时候,
在窗体上放入一个文本框用户客户的输入;
现在用户选择了输入信息中的一部分,然后对其进行操作。
我如何判断用户现在的那个字符?
...全文
135 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tinary3v0 2008-12-09
  • 打赏
  • 举报
回复
去PreTranslateMsg里面截获你要处理的消息。
例如:WM_LBUTTONUP 然后在PreTranslateMsg里面使用GetSel获得当前选中的文字。

如果放在别的地方的话可能就得不到你要的效果了。因为程序本身消息循环可能会跳过你要的那个阶段,造成你得到的选中文字为空的后果。
bai_hua_lin 2008-12-09
  • 打赏
  • 举报
回复
这个编辑框有个消息是响应用户选择的,你实现这个消息响应函数就可以了。
来灵 2008-12-08
  • 打赏
  • 举报
回复
void GetSel(
int& nStartChar,
int& nEndChar )
const;

nStartChar
Specifies the reference to an integer that will receive the position of the first character in the current selection.
nEndChar
Specifies the reference to an integer that will receive the position of the first nonselected character past the end of the current selection.
jiyuanjie 2008-12-08
  • 打赏
  • 举报
回复
int ReadSelText(CString& str)
{
int selStart, selEnd;
CString str;
m_myEdit.GetSel( selStart, selEnd ); //获取当前选择的位置, m_myEdit是edit控件的变量
int selLen = selEnd-selStart; //求选择区长度
if( selLen )
{
CString text;
GetDlgItemText( IDC_EDIT1,text ); //获取控件文本,IDC_EDIT是控件ID
str = text.Mid( selStart, selLen ); //获取选择的文本
}
else
str = _T("");
return selLen;
}
cnzdgs 2008-12-08
  • 打赏
  • 举报
回复
“用户现在的那个字符”是什么意思?
如果想要知道用户选择了哪些字符,可以用CEdit类的GetSel函数。
ivan_08 2008-12-08
  • 打赏
  • 举报
回复
楼主输入的是CString才可以啊,因为不仅仅是数字还可能有字母,我也在思考这个东西,还在找解决方案中
Chivalry 2008-12-08
  • 打赏
  • 举报
回复
int nStartChar;
int nEndChar;
CString rString;

m_Edit.GetSel(nStartChar,nEndChar);
m_Edit.GetWindowText(rString);
MessageBox(rString.Mid(nStartChar,nEndChar - nStartChar));
oh_my_god 2008-12-08
  • 打赏
  • 举报
回复
CEdit 的GetSel函数
liviatt 2008-12-08
  • 打赏
  • 举报
回复
如何判断用户现在的那个字符? ??说清楚了是什么呀

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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