[MFC][CEdit][基本函数]CEdit::GetLine与CEdit::LineIndex

本文介绍了MFC中CEdit控件的两个关键函数:GetLine和LineIndex。GetLine用于获取指定行的文本内容,返回实际拷贝的字节数,而LineIndex则返回某一行的字符下标。文章详细解析了两个函数的参数及返回值,并指出CEdit的默认最大显示字符数和如何设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

GetLine:从编辑控件中检取一行文本。没有文本,返回拷贝的字节数。如果nIndex参数指定的行号大于编辑控件中的参数,返回0。nIndex指定要从控件中检取的行号,为0,指定第一行。   

CEdit::GetLine

int GetLine( int nIndex, LPTSTR lpszBuffer ) const;

int GetLine( int nIndex, LPTSTR lpszBuffer, int nMaxLength ) const;

Return Value

The number of bytes actually copied. The return value is 0 if the line number specified by nIndex is greater then the number of lines in the edit control.

Parameters

nIndex

Specifies the line number to retrieve from a multiple-line edit control. Line numbers are zero-based; a value of 0 specifies the first line. This parameter is ignored by a single-line edit control.

lpszBuffer

Points to the buffer that receives a copy of the line. The first word of the buffer must specify the maximum number of bytes that can be copied to the buffer.

nMaxLength

Specifies the maximum number of bytes that can be copied to the buffer. GetLine places this value in the first word of lpszBuffer before making the call to Windows.  

 

  
LineIndex:检取多行控件中某一行的字符下标。如果指定行号大于编辑控件中的行数,返回-1。参数nLine表示行在编辑控件文本中的下标值或-1。为-1,指定当前行,即包含插入符的行。多行时返回指定(当前)行的字符序号 只用于多行时

 

索引从0开始

CEdit::LineIndex

int LineIndex( int nLine = -1 ) const;

Return Value

The 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.

Parameters

nLine

Contains the index value for the desired line in the text of the edit control, or contains –1. If nLine is –1, it specifies the current line, that is, the line that contains the caret.

Remarks

Call this function to retrieve the character index of a line within a multiple-line edit control. The character index is the number of characters from the beginning of the edit control to the specified line.

This member function is only processed by multiple-line edit controls.

 

CEdit默认最大显示字符数是30000,可以使用SetLimitText 进行设置

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值