This example demonstrates a simply way to get information from a RichTextBox
that is often displayed in a status bar (ie number of lines, current line, column
etc). This code uses API calls in some cases, and expects the RichTextBox to
be called rtfMain.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
As Long
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETFIRSTVISIBLELINE = &HCE
Private Const EM_GETLINECOUNT = &HBA
Public Property Get LineCount() As Long
LineCount = SendMessage(rtfMain.hwnd, EM_GETLINECOUNT,
0&, 0&)
End Property
Public Property Get GetFirstLineVisible() As Long
GetFirstLineVisible = SendMessage(rtfMain.hwnd, EM_GETFIRSTVISIBLELINE,
0&, 0&)
End Property
Public Property Get CurrentColumn() As Long
Dim lCurLine As Long
' Current Line
lCurLine = 1 + rtfMain.GetLineFromChar(rtfMain.SelStart)
' Column
CurrentColumn = SendMessage(rtfMain.hwnd, EM_LINEINDEX,
ByVal lCurLine - 1, 0&)
CurrentColumn = (rtfMain.SelStart) - CurrentColumn
End Property
Public Property Get CurrentLine() As Long
CurrentLine = 1 + rtfMain.GetLineFromChar(rtfMain.SelStart)
End Property