|
Расположите на форме элемент CommandButton и
элемент TextBox. Установите свойство Multiline
элемента TextBox как True.
Синтаксис вызова функции прост: GetLine(НазваниеОкна.hWnd,
НомерСтроки). Данный пример (при нажатии на
кнопку) покажет содержимое 2-й строки элемента TextBox. Private Declare Function SendMessage Lib "user32" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wp As Long, lp As
Any) As Long
Const EM_LINEINDEX = &HBB
Const EM_LINELENGTH = &HC1
Const EM_GETLINE = &HC4
Public Function GetLine(hWnd As Long, Line As Long) As String
Dim sBuf As String, nLen As Long, nIndex As Long
nIndex = SendMessage(hWnd, EM_LINEINDEX, Line - 1, ByVal 0&)
If nIndex < 0 Or Line <= 0 Then Exit Function
nLen = SendMessage(hWnd, EM_LINELENGTH, nIndex, ByVal 0&)
sBuf = Space(nLen + 1)
Mid$(sBuf, 1, 1) = Chr$(nLen And &HFF)
Mid$(sBuf, 2, 1) = Chr$(nLen \ 256)
SendMessage hWnd, EM_GETLINE, Line - 1, ByVal sBuf
GetLine = Left$(sBuf, nLen)
End Function
Private Sub Form_Load()
Text1.Text = "1111111" & vbCrLf & "22222" & vbCrLf &
"3333" & vbCrLf & "4444"
End Sub
Private Sub Command1_Click()
MsgBox GetLine(Text1.hWnd, 2)
End Sub
|
|