专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > vbScript

怎样获取 edit控件读取每行信息的字符个数?解决办法

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
怎样获取 edit控件读取每行信息的字符个数??
我现在需要获取EDIT 控件里每行的信息,我用的是 CEdit pEdit; pEdit.GetLine(0,ctestline,100); 根据GetLine函数的定义,第二个参数因为存放 改行信息的字符数组,但是现在不小的该行的字符个数到底是多少?请问高手,怎末样获取啊 ,,,没有个数怎末样建立字符数组啊 ,不要说动态数组,动态数组也是要获取大小先的。。。小弟在线等牛人你解答!!感激不禁!!

------解决方案--------------------
C/C++ code

   extern CEdit* pmyEdit;    // The pointer to my edit control:

   int i, nLineCount = pmyEdit->GetLineCount();
   CString strText, strLine;
   // Dump every line of text of the edit control.
   for (i=0;i < nLineCount;i++)
   {
      // length of line i:
      int len = pmyEdit->LineLength(pmyEdit->LineIndex(i));
      pmyEdit->GetLine(i, strText.GetBuffer(len), len);
      strText.ReleaseBuffer(len);
      strLine.Format(TEXT("line %d: '%s'n"), i, strText);
      afxDump << strLine;
   }

------解决方案--------------------
EM_GETLINE Message
看MSDN , 不能直接取到



不过你可以这样做:

The copied line does not contain a terminating null character.
它返回的字符串是包含null字符串的

而它的返回值是
The return value is the number of TCHARs copied. The return value is zero if the line number specified by the wParam parameter is greater than the number of lines in the edit control.

那么,可以用一个循环。
首先用长度为100 的TCHAR获取, 如果返回值显示还有未读取完的, 则增加一倍缓存区。 继续读。
知道读取完成 再退出此循环
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: