Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleSee when a TextBox is displaying its last line
KeywordsTextBox, display, last line, sendmessage
CategoriesControls
 
Use a timer that sends the control the EM_GETRECT message to see how big the TextBox is. Then use EM_CHARFROMPOS to see what character is at the bottom of the control. If it is the last character, the last line is displayed.
 
Private Sub Text1_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim pos As Long

    ' Get the position of the bottom of the control.
    X = CLng(ScaleX(X, ScaleMode, vbPixels))
    Y = CLng(ScaleY(Y, ScaleMode, vbPixels))

    ' Get the character number
    pos = SendMessageLong(Text1.hWnd, EM_CHARFROMPOS, _
        0&, X + Y * &H10000) And &HFFFF&

    If pos >= Len(Text1.Text) Then
        Command1.Enabled = True
    End If
End Sub

' See if the last line is visible.
Private Sub Timer1_Timer()
Static done_before As Boolean
Static X As Long
Static Y As Long

Dim r As RECT
Dim pos As Long

    ' Get text box's client rectangle size.
    If Not done_before Then
        SendMessageAny Text1.hWnd, EM_GETRECT, 0&, r
        X = r.Right - 1
        Y = r.Bottom - 1
        done_before = True
    End If

    ' Get the character number
    pos = SendMessageLong(Text1.hWnd, _
        EM_CHARFROMPOS, 0&, X + Y * &H10000) _
            And &HFFFF&

    If pos >= Len(Text1.Text) Then
        Command1.Enabled = True
        Timer1.Enabled = False
    End If
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated