CEdit类里的LineLength函数是怎么用的啊? 
我是这样调用的: 
CEdit theEdit;//这个theEdit已经获得当前cedit控件的句柄的了。 
CString set;//用来测试bufsize的值。 
lineno=0; 
while(theEdit->LineIndex(lineno)!=-1)//当没有到最后一行时 

bufsize=theEdit->LineLength(lineno++); 
set.Format("bufsize=%d,lineno=%d",bufsize,lineno); 
MessageBox(set); 

但bufsize的值没有象预期中地变,而是很奇怪的。。 
假设我的控件里的第一行的文字是:abcdefg 七个字母 
其他行的并不是七个字母的 
但messagebox显示的是: 
bufsize=7,lineno=1 
bufsize=7,lineno=2 
bufsize=7,lineno=3 bufsize=7,lineno=4 
bufsize=7,lineno=5 
bufsize=7,lineno=6 
bufsize=7,lineno=7 
bufsize=7,lineno=8 
就是说bufsize会保持八次不变,怎么回事呢?

解决方案 »

  1.   

    对LineIndex()的理解有误,它返回的不是行号,而是总的字符索引。
      

  2.   

    我是看msdn的。
    int LineIndex( int nLine = -1 ) const;Return ValueThe character index of the line specified in nLine or –1 if the specified line number is greater then the number of lines in the edit control.
    就是说当行数大于edit控件中的总行数时就会返回-1的吧?
    但这个不是主要问题,我是想知道bufsize的值为什么不会随着行号变的呢?
      

  3.   

    多行Cedit调用它的时候,总是返回第一行的长度.
      

  4.   

    多行Cedit调用它的时候,总是返回第一行的长度.
    好象是这样的
      

  5.   

    并不是只返回第一行的长度的,,我试过,它返回n次第一行的长度,而这个n值正是第一行的字符数+1。之后是返回第二行的长度,也是重复(第二行的字符数+1)次,直到末行,难道有什么参数没设好?到底怎么回事?
    linelength(int nline)在msdn里明明是说返回第nline行的字符数的啊。。,
      

  6.   

    up up....
    555,怎么没人回答一下啊
      

  7.   

    int LineLength( int nLine = -1 ) constParametersnLineSpecifies the character index of a character in the line whose length is to be retrieved. If this parameter is –1, the length of the current line (the line that contains the caret) is returned, not including the length of any selected text within the line. When LineLength is called for a single-line edit control, this parameter is ignored.确定要检索的行的字符索引,若参数为-1,则返回目前行的长度,不包含这行中任何选定的文本长,当此函数被single-line edit control调用时,此参数忽略!我的e文不太好,包涵!!!
      

  8.   

    谢谢,呵呵,我看得是它的返回值的说明。
    int LineLength( int nLine = -1 ) const;Return ValueWhen LineLength is called for a multiple-line edit control, the return value is the length (in bytes) of the line specified by 
                                                      ~~~~~~~~~~~~
    nLine. When LineLength is called for a single-line edit control,
    ~~~~~~这里的意思是不是nline应该是整个edit控件里的索引值呢?恩,我想应该是了。试试先。。:)
     the return value is the length (in bytes) of the text in the edit control.