Function Reference


_GUICtrlRichEdit_GetXYFromCharPos

Retrieves the XY coordinates of an inter-character position

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_GetXYFromCharPos ( $hWnd, $iCharPos )

Parameters

$hWnd Handle to the control
$iCharPos Inter-character position

Return Value

Success: an array [, ] - coordinates of the inter-character position, relative to the top-left corner of the client area.
Failure: sets the @error flag to non-zero.
@error: 101 - $hWnd is not a handle
1021 - $iCharPos is neither a positive number nor zero
1022 - $iCharPos exceeds the number of characters in the control

Remarks

The first inter-character position is numbered 0.

With a multi-line control, coordinates are returned even for inter-character positions that are not visible.

Related

_GUICtrlRichEdit_GetCharPosFromXY

See Also

Search EM_POSFROMCHAR in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Global $g_idLblMsg

Example()

Func Example()
        Local $hGui, $hRichEdit, $iMsg, $aiPos, $idBtnNext, $iStep = 0
        $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1)
        $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
        $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
        $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
        GUISetState(@SW_SHOW)

        _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "This is appended text.")

        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                ; GUIDelete()   ; is OK too
                                Exit
                        Case $iMsg = $idBtnNext
                                $iStep += 1
                                Switch $iStep
                                        Case 1
                                                $aiPos = _GUICtrlRichEdit_GetXYFromCharPos($hRichEdit, 20)
                                                Report("1.The coordinates of inter-character position 20 are (" & $aiPos[0] & "," & $aiPos[1] & ")")
                                        Case 2
                                                Report("2.The inter-character position at or nearest coordinates (" & $aiPos[0] & "," & $aiPos[1] & ") is " & _
                                                                _GUICtrlRichEdit_GetCharPosFromXY($hRichEdit, $aiPos[0], $aiPos[1]))
                                                GUICtrlSetState($idBtnNext, $GUI_DISABLE)
                                EndSwitch
                EndSelect
        WEnd
EndFunc   ;==>Example

Func Report($sMsg)
        GUICtrlSetData($g_idLblMsg, $sMsg)
EndFunc   ;==>Report