Results 1 to 5 of 5

Thread: RichTextBox Cursor Position

  1. #1

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Unhappy

    Hi,
    Has anybody got any idea as to how I can find out the current X,Y positions of a cursor in a richtextbox.

    Thanks in advance

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Shaun,

    I just tried this code, and it tells you how many characters from the beginning the cursor is currently sitting at, the value gets stored in Endselect.

    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_GETSEL = &HB0

    Private Sub Command1_Click()
    Dim StartSelect, Endselect As Long
    SendMessage RichTextBox1.hwnd, EM_GETSEL, StartSelect, Endselect
    End Sub

    Try it, see what you think...
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi crispin,
    Thanks for that, but it's not really what I'm looking for.
    With your example, If the user selects a different font then, yes, the position in characters will stay the same but the cursor may be in a totally different place dependant on the font width.
    I have tried using the GetCursorPos API without much success. It seems to be returning all sorts of different values!

    Has anyone else got any ideas on how to get the X,Y position of the cursor in a RichTextBox???

    Thanks

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  4. #4
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
    x As Long
    y As Long
    End Type

    Private Sub Command1_Click()
    Dim posX As POINTAPI
    Dim iResult
    iResult = GetCaretPos(posX)
    MsgBox "X = " & posX.x & " Y = " & posX.y
    End Sub

    I think this works...(you are trying to get the flashing cursor position and not the mouse cursor position aren't you? - otherwise i'm barking up the wrong tree completely
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  5. #5

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Thumbs up

    That's the one

    Cheers for your help

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width