No announcement yet.

Get current position in a textbox

  • Filter
  • Time
  • Show
Clear All
new posts

  • Get current position in a textbox

    Hi Everyone:

    I'm using DDT to write a small editor with basic spell-checking functions, and have successfully put a status line at the bottom of the screen which spell-checks each line in the editbox and displays misspelled words as the user cursors through it. What I'd like to do now is when the user highlightes a misspelled word in the document with the right or left arrows, have suggestions appear at the bottom of the screen of acceptable words. This magical snipit of code gives me the current line number:

    CONTROL SEND hWnd&, 101, %EM_LINEFROMCHAR, -1, %NULL TO CurrentLine

    but I can't seem to get the current position on the current line. I thought for sure that %EM_POSFROMCHAR would give me the X position on the line, but it doesn't. Any ideas?

    One other thing. I would really like to add a feature where I can tell my editor to go to a specific line number like some really nice DOS editors used to have, but I don't know how to reposition the curser at the new line number. Another %EM_* Message?

    Thank you! I've spent a morning pouring over %EM_* messages, faithfully trying each and every one. I've gotten some of the strangest numbers ever, but I can't make sence out of any of them at all.

    [This message has been edited by Danny Faris (edited September 08, 2000).]

  • #2
    Maybe this will work: (for normal edit control)
      LOCAL selStart AS LONG, selEnd AS LONG, LinePos AS LONG
      CONTROL SEND hWnd&, 101, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)
      CONTROL SEND hWnd&, 101, %EM_LINEINDEX, -1, 0 TO LinePos
      LinePos = selStart - LinePos + 1  '<- position on line
    ..and this one for a simple Goto Line routine:
    SUB GotoLine(BYVAL lNum AS LONG)
      LOCAL LinePos AS LONG
      DECR lNum  ' zero based index
      IF lNum < 0 THEN lNum = 0
      CONTROL SEND hWnd&, 101, %EM_LINEINDEX, lNum, 0 TO LinePos
      CONTROL SEND hWnd&, 101, %EM_SETSEL, LinePos, LinePos


    [This message has been edited by Borje Hagsten (edited September 08, 2000).]


    • #3
      Hi Borje:
      You are so very clever! Both of those marvelous code samples worked flawlessly! The goto feature is great. It's really fast, too - faster than I had dared to hope for. And getting the current character works super! Thank you so much for all your help; I really appreciate it!

      Take care