UDF > GUI > GuiRichEdit >


_GUICtrlRichEdit_GetCharPosFromXY

Obtient la position inter-caractères la plus proche d'un point donné dans la zone client

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_GetCharPosFromXY ( $hWnd, $iX, $iY )

Paramètres

$hWnd Handle du contrôle
$iX Coordonnée horizontale par rapport au côté gauche du contrôle
$iY Coordonnée verticale par rapport au haut du contrôle

Valeur de retour

Succès: Retourne l'index, à partir de 0, du caractère le plus proche du point spécifié
    (index du caractère au bord du contrôle si le point spécifié est au-delà du texte).
Échec: Retourne 0 et définit @error <> 0.
@error: 101 - $hWnd n'est pas une handle
102 - $iX est pas un nombre
103 - $iy n'est pas un nombre
-1 - ($IX, $iy) est un point hors de la zone client

En relation

_GUICtrlRichEdit_GetXYFromCharPos

Voir aussi

Consultez EM_CHARFROMPOS dans la librairie MSDN.

Exemple

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

Global $g_idLblMsg

Example()

Func Example()
    Local $hGui, $iMsg, $aiPos, $idBtnNext, $hRichEdit, $iStep = 0
    $hGui = GUICreate("Exemple (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "Ceci est un test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    $idBtnNext = GUICtrlCreateButton("Suivant", 270, 310, 40, 30)
    GUISetState(@SW_SHOW)

    _GUICtrlRichEdit_AppendText($hRichEdit, @CRLF & "Ceci est du texte ajouté.")

    $iMsg = GUIGetMsg()
    While $iMsg <> $GUI_EVENT_CLOSE 
        If $iMsg = $idBtnNext Then
            $iStep += 1
            Switch $iStep
                Case 1
                    $aiPos = _GUICtrlRichEdit_GetXYFromCharPos($hRichEdit, 20)
                    Report("1.Les coordonnées de la position inter-caractères 20 sont (" & $aiPos[0] & "," & $aiPos[1] & ")")
                Case 2
                    Report("2.La position inter-caractères la plus proche des coordonnées (" & $aiPos[0] & "," & $aiPos[1] & ")" & @CRLF & _
                            "est " & _GUICtrlRichEdit_GetCharPosFromXY($hRichEdit, $aiPos[0], $aiPos[1]))
                    GUICtrlSetState($idBtnNext, $GUI_DISABLE)
            EndSwitch
        EndIf
    Wend

    _GUICtrlRichEdit_Destroy($hRichEdit) ; Nécessaire sauf si le script se bloque
    ; GUIDelete(); est OK aussi
EndFunc   ;==>Example

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