How can you get the line number in a multiline text box?
Printable View
How can you get the line number in a multiline text box?
TextboxLine has the current line (one with the caret)Code:
long TextBoxLine = SendMessage( hWnd, EM_LINEINDEX, (-1), 0L);
hWnd is the hWnd of the textbox.
I think you need to use the EM_LINEFROMCHAR message to get the line number of the caret.
Not according to MSDN. This gets the active line
I believe you are incorrect.
Quote:
from MSDN
The EM_LINEINDEX message retrieves the character index of the first character of a specified line in a multiline edit control.
wParam
Specifies the zero-based line number. A value of –1 specifies the current line number (the line that contains the caret).
------------------------------------------------------------------------------
The EM_LINEFROMCHAR message retrieves the index of the line that contains the specified character index in a multiline edit control.
wParam
Specifies the character index of the character contained in the line whose number is to be retrieved. If this parameter is –1, EM_LINEFROMCHAR retrieves either the line number of the current line (the line containing the caret) or, if there is a selection, the line number of the line containing the beginning of the selection.
what is that "OL" for?
It specifies that you specifically want a "long", not an "int" in the parameter. Almost irrelevant with C++ because it'll coerce the types anyway.
it's the same as (long)0
which is irrelevant as parksie said.