首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > vbScript >

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

2012-05-07 
怎样获取 edit控件读取每行信息的字符个数??我现在需要获取EDIT 控件里每行的信息,我用的是CEdit pEditpE

怎样获取 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获取, 如果返回值显示还有未读取完的, 则增加一倍缓存区。 继续读。
知道读取完成 再退出此循环

热点排行