关于CEdit中的LineLength和LineIndex的使用

来源:互联网 发布:现代四大名著网络 编辑:程序博客网 时间:2024/06/05 21:52

先举个例子:
http://msdn.microsoft.com/zh-cn/library/90dfhy8f(v=vs.80).aspx

// The pointer to my edit.extern CEdit* pmyEdit;// The string for replacing.extern LPCTSTR lpszmyString;int nBegin, nEnd;   // Replace the second line, if it exists, of the edit control// with the text lpszmyString.if ((nBegin=pmyEdit->LineIndex(1)) != -1){   nEnd = nBegin + pmyEdit->LineLength(nBegin);    pmyEdit->SetSel(nBegin, nEnd);   pmyEdit->ReplaceSel(lpszmyString);}
上述例子是将第2行的字符,lpszmyString来代替。


再自己写个函数例子:

1.Cedit控件里,先初始化以下内容:

天下会\r\n

1234回击\r\n

99887766

2.如下代码:

    int nLineIndex[3] = {0}, nLineLen[3] = {0};    nLineIndex[0] = m_edit_ctrl.LineIndex(0);    nLineIndex[1] = m_edit_ctrl.LineIndex(1);    nLineIndex[2] = m_edit_ctrl.LineIndex(2);    nLineLen[0] = m_edit_ctrl.LineLength(nLineIndex[0]);    nLineLen[1] = m_edit_ctrl.LineLength(nLineIndex[1]);    nLineLen[2] = m_edit_ctrl.LineLength(nLineIndex[2]);

nLineIndex的结果:0,5,13,返回的是某一行首个字符序号,包括\r\n
nLineLen的结果:3,6,8,返回的是某个字符序号所在行的长度,不包括\r\n,即这里填的参数是字符序号

3.如上的结果,可以看出是字符,不是字节,但是在_MBCS下是按照字节计算的,与unicode不同。特别提一下,使用.manifest的时候也是按照字符计 算的,原因不知道。


0 0