Vielleicht gibt es ja einen einfacheren Weg, aber ich würde es so machen:
Code: Alles auswählen
Procedure EGCursorLine(gadget)
SendMessage_(GadgetID(gadget),#EM_EXGETSEL,0,Range.CHARRANGE)
ProcedureReturn SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin)
EndProcedure
Procedure EGCursorCharPos(gadget) ; returns X-Pos of Cursor
REG = GadgetID(gadget)
SendMessage_(REG,#EM_EXGETSEL,0,Range.CHARRANGE)
ProcedureReturn (Range\cpMax-(SendMessage_(REG,#EM_LINEINDEX,SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin),0))+1)
EndProcedure
Procedure.w GetWordStartPos(thText.s, thPos.w) ; Search position of first character from word
If Mid(thText, thPos, 1) < "A" Or Mid(thText, thPos, 1) > "z" : ProcedureReturn thPos : EndIf
Repeat
thPos - 1
Until Mid(thText, thPos, 1) = " " Or thPos <= 1
If Mid(thText, thPos, 1) = " "
ProcedureReturn thPos + 1
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure.w GetWordEndPos(thText.s, thPos.w) ; Search position of last character from a word
If Mid(thText, thPos, 1) < "A" Or Mid(thText, thPos, 1) > "z" : ProcedureReturn thPos : EndIf
Repeat
thPos + 1
Until Asc(Mid(thText, thPos, 1)) < 65 Or Asc(Mid(thText, thPos, 1)) > 122 Or thPos >= Len(thText)
If thPos <= Len(thText)
ProcedureReturn thPos - 1
Else
ProcedureReturn Len(thText)
EndIf
EndProcedure
Procedure.s GetWord(text$, pos.w)
wpos1.w = GetWordStartPos(text$, pos)
ProcedureReturn Mid(text$, wpos1, GetWordEndPos(text$, pos) - wpos1 +1)
EndProcedure
hwnd = OpenWindow(0,0,0,300,300,"")
If CreateGadgetList(hwnd)
hedit = EditorGadget(0,10,10,280,280)
EndIf
SetGadgetText(0, "Das ist ein Testtext.")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
; ......
EndIf
zeile$ = GetGadgetItemText(0,EGCursorLine(0),#Null)
wort$ = GetWord(zeile$, EGCursorCharPos(0))
SetWindowText_(WindowID(0), "Wort: " + wort$ + " ("+Str(EGCursorCharPos(0))+")")
Until event = 16