EM_LINEINDEX
An application sends an EM_LINEINDEX message to retrieve the character index of a line in a multiline edit control. The character index is the number of characters from the beginning of the edit control to the specified line. EM_LINEINDEX
wParam = (WPARAM) line; // line number
lParam = 0; // not used; must be zero
Parameters
line
Value of wParam. Specifies the zero-based line number. A value of –1 specifies the current line number (the line that contains the caret).
Return Values
The return value is the character index of the line specified in the line parameter, or it is –1 if the specified line number is greater than the number of lines in the edit control. EM_LINELENGTH
An application sends an EM_LINELENGTH message to retrieve the length of a line, in characters, in an edit control. EM_LINELENGTH
wParam = (WPARAM) ich; // character index
lParam = 0; // not used; must be zero
Parameters
ich
Value of wParam. Specifies the character index of a character in the line whose length is to be retrieved when EM_LINELENGTH is sent to a multiline edit control. If this parameter is –1, the message returns the number of unselected characters on lines containing selected characters. For example, if the selection extended from the fourth character of one line through the eighth character from the end of the next line, the return value would be 10 (three characters on the first line and seven on the next).
Return Values
The return value is the length, in characters, of the line specified by the ich parameter when an EM_LINELENGTH message is sent to a multiline edit control. The return value is the length, in characters, of the text in the edit control when an EM_LINELENGTH message is sent to a single-line edit control. Res
Use the EM_LINEINDEX message to retrieve a character index for a given line number within a multiline edit control.
An application sends an EM_LINEINDEX message to retrieve the character index of a line in a multiline edit control. The character index is the number of characters from the beginning of the edit control to the specified line. EM_LINEINDEX
wParam = (WPARAM) line; // line number
lParam = 0; // not used; must be zero
Parameters
line
Value of wParam. Specifies the zero-based line number. A value of –1 specifies the current line number (the line that contains the caret).
Return Values
The return value is the character index of the line specified in the line parameter, or it is –1 if the specified line number is greater than the number of lines in the edit control. EM_LINELENGTH
An application sends an EM_LINELENGTH message to retrieve the length of a line, in characters, in an edit control. EM_LINELENGTH
wParam = (WPARAM) ich; // character index
lParam = 0; // not used; must be zero
Parameters
ich
Value of wParam. Specifies the character index of a character in the line whose length is to be retrieved when EM_LINELENGTH is sent to a multiline edit control. If this parameter is –1, the message returns the number of unselected characters on lines containing selected characters. For example, if the selection extended from the fourth character of one line through the eighth character from the end of the next line, the return value would be 10 (three characters on the first line and seven on the next).
Return Values
The return value is the length, in characters, of the line specified by the ich parameter when an EM_LINELENGTH message is sent to a multiline edit control. The return value is the length, in characters, of the text in the edit control when an EM_LINELENGTH message is sent to a single-line edit control. Res
Use the EM_LINEINDEX message to retrieve a character index for a given line number within a multiline edit control.
An application sends an EM_GETLINECOUNT message to retrieve the number of lines in a multiline edit control. EM_GETLINECOUNT
wParam = 0; // not used; must be zero
lParam = 0; // not used; must be zero
Parameters
This message has no parameters. Return Values
The return value is an integer specifying the number of lines in the multiline edit control. If no text is in the edit control, the return value is 1.
发送EM_LINELENGTH消息,确定N的范围
TempLng=SendMessage(Text1.hWnd, EM_LINEINDEX, M, ByVal 0&) + N
Call SendMessage(Text1.hWnd, EM_SETSEL, TempLng, ByVal TempLng)要注意:
行号从0开始
VB使用的是UniCode,所以不能用Sel……属性EM_SETSEL
An application sends an EM_SETSEL message to select a range of characters in an edit control. EM_SETSEL
wParam = (WPARAM) (INT) nStart; // starting position
lParam = (LPARAM) (INT) nEnd; // ending position
Parameters
nStart
Value of wParam. Specifies the starting character position of the selection.
nEnd
Specifies the ending character position of the selection.
Return Values
This message does not return a value. Res
In a rich edit control, if the selection is not entirely contained in the first 64K, use the message EM_EXSETSEL.If the nStart parameter is 0 and the nEnd parameter is –1, all the text in the edit control is selected. If nStart is –1, any current selection is removed. The caret is placed at the end of the selection indicated by the greater of the two values nEnd and nStart.
x= SendMessage( txtBox.hWnd, EM_LINEINDEX, LineIndex, 0&)'行号从0开始
Public Const EM_GETLINE = &HC4
Public Const EM_LINELENGTH = &HC1
Public Const EM_LINEINDEX = &HBBPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Option ExplicitOption ExplicitPrivate Sub Command1_Click()Dim Whichline As Long
Whichline = 2
Dim length As Long, bArr() As Byte, bArr2() As Byte, lc As Longlc = SendMessage(Text1.hWnd, EM_LINEINDEX, Whichline, ByVal 0&)length = SendMessage(Text1.hWnd, EM_LINELENGTH, lc, ByVal 0&)
End Sub
结果是LC是23,LENGTH是0,为什么?