22 de octubre de 2007

Cómo obtener la palabra bajo el cursor en un control editbox

Ejemplo de cómo obtener la palabra bajo el cursor en un control editbox.

PUBLIC oForm1

oForm1 = NEWOBJECT("Form1")
oForm1.SHOW
RETURN

DEFINE CLASS Form1 AS FORM
  TOP = 0
  LEFT = 0
  HEIGHT = 276
  WIDTH = 419
  DOCREATE = .T.
  CAPTION = "Form1"
  ALLOWOUTPUT = .F.
  NAME = "Form1"

  ADD OBJECT Edit1 AS EDITBOX WITH ;
    FONTNAME = "Tahoma", FONTSIZE = 8, NAME = "Edit1", ;
    ANCHOR = 15, HEIGHT = 217, LEFT = 12, TOP = 12, WIDTH = 397, ;
    VALUE = [In Windows© XP®, {owner/draw} menus show icons, but Windows Vista® uses ] ;
    + [alpha-blended bitmaps instead.] + CHR(13) + CHR(10) ;
    + [Windows Vista "provides" menus are (part of) the 'visual schema'. ] ;
    + CHR(13) + CHR(10) ;
    + [Using a destroyed menu handle] + CHR(13) + CHR(10)

  ADD OBJECT Timer1 AS TIMER WITH ;
    TOP = 216, LEFT = 0, HEIGHT = 23, WIDTH = 23, ;
    INTERVAL = 100, NAME = "Timer1"

  ADD OBJECT Text1 AS TEXTBOX WITH ;
    FONTNAME = "Tahoma", FONTSIZE = 8, ;
    HEIGHT = 23, LEFT = 12, TOP = 240, WIDTH = 396, ;
    ANCHOR = 14, READONLY = .T., NAME = "Text1"

  PROCEDURE Edit1.KEYPRESS
    LPARAMETERS nKeyCode, nShiftAltCtrl
    *!* We have to use a timer to get out of the KeyPress event loop
    *!* because Selstart and SelLength get updated AFTER pressing
    *!* the left/right arrow keys, but does NOT get updated
    *!* after pressing up/down arrow keys
    THISFORM.Timer1.ENABLED = .T.
  ENDPROC

  PROCEDURE Edit1.MOUSEUP
    LPARAMETERS nButton, nShift, nXCoord, nYCoord
    THISFORM.Timer1.ENABLED = .T.
  ENDPROC

  PROCEDURE Timer1.TIMER
    THIS.ENABLED = .F.
    m.loEdit = THISFORM.edit1
    m.charfilter = " ,;.:[]{}()/\'®©<>" + '"' + CHR(13) + CHR(0)
    m.lcWord = ""
    m.lcChar = ""
    *!* 25 arbitrary limit for search, just in case
    FOR m.lnx = 0 TO 25
      m.lcWord = m.lcChar + m.lcWord
      m.lcChar = SUBSTR(m.loEdit.TEXT, m.loEdit.SELSTART + m.loEdit.SELLENGTH - m.lnx, 1)
      IF m.lcChar $ m.charfilter
        EXIT
      ENDIF
    ENDFOR
    m.lcChar = ""
    FOR m.lnx = 1 TO 25
      m.lcWord = m.lcWord + m.lcChar
      m.lcChar = SUBSTR(m.loEdit.TEXT, m.loEdit.SELSTART + m.loEdit.SELLENGTH + m.lnx, 1)
      IF m.lcChar $ m.charfilter
        EXIT
      ENDIF
    ENDFOR
    THISFORM.text1.VALUE = m.lcWord
    m.loEdit = NULL
  ENDPROC

ENDDEFINE

Carlos Alloatti

No hay comentarios. :

Publicar un comentario

Los comentarios son moderados, por lo que pueden demorar varias horas para su publicación.