CEdit::LineFromChar
更新 : 2007 年 11 月
指定された文字インデックスを持つ行の行番号を取得します。
int LineFromChar(
int nIndex = -1
) const;
パラメータ
- nIndex
エディット コントロールのテキスト内の目的の文字を 0 から始まるインデックス値で指定します。または、-1 を指定することもできます。nIndex が -1 のときは、現在行 (キャレットのある行) を示します。
戻り値
nIndex で指定されている文字インデックスを格納している行の値を 0 から始まる行番号で返します。nIndex が -1 の場合は、選択されたテキストの先頭文字を含む行の行番号を返します。何も選択されていない場合は、現在の行番号を返します。
解説
文字インデックスは、エディット コントロールの先頭からの文字数です。
このメンバ関数は、複数行のエディット コントロールでのみ利用できます。
詳細については、Windows SDK の「EM_LINEFROMCHAR」を参照してください。
使用例
// The index of the char to get information on.
int nIndex = 4;
CString strText;
m_myEdit.GetWindowText(strText);
strText = strText.Mid(nIndex, 1);
// Get the text extent of the character.
CDC* pDC = m_myEdit.GetDC();
CSize sz = pDC->GetTextExtent(strText);
m_myEdit.ReleaseDC(pDC);
CPoint pt = m_myEdit.PosFromChar(nIndex);
// Dump the index, character, line number, and character bounds.
TRACE(_T("nIndex = %d, character = %c, line = %d, bounds = ")
_T("{%d, %d, %d, %d}\r\n"),
nIndex, strText[0], m_myEdit.LineFromChar(nIndex),
pt.x /* left */, pt.y /* top */,
pt.x+sz.cx /* right */, pt.y+sz.cy /* bottom */);
必要条件
ヘッダー : afxwin.h