获取最接近客户区指定点的字符区间位置
#Include <GuiRichEdit.au3>
_GUICtrlRichEdit_GetCharPosFromXY($hWnd, $iX, $iY)
$hWnd | 控件句柄 |
$iX | 相对于控件左侧的水平屏幕坐标 |
$iY | 相对于控件顶部的垂直屏幕坐标 |
成功: | 返回最接近指定点的字符 0 基索引 | |
(如果指定点在文字以外,则返回控件最后一个字符的索引) | ||
失败: | 返回 0,设置@error: | |
@error: | 101 - $hWnd 参数值不是句柄 | |
102 - $iX 不是一个数字 | ||
103 - $iY 不是一个数字 | ||
-1 - ($iX,$iY) 在客户区外部 |
在MSDN中搜索
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $lblMsg, $hRichEdit
Main()
Func Main()
Local $hGui, $iMsg, $ai, $btnNext, $iStep = 0
$hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _
BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
$btnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
GUISetState()
_GUICtrlRichEdit_AppendText($hRichEdit, @CR & "This is appended text.")
While True
$iMsg = GUIGetMsg()
Select
Case $iMsg = $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($hRichEdit) ; 除非脚本崩溃才需要
;~ GUIDelete() ; 同样行
Exit
Case $iMsg = $btnNext
$iStep += 1
Switch $iStep
Case 1
$ai = _GUICtrlRichEdit_GetXYFromCharPos($hRichEdit, 20)
Report("1.The coordinates of inter-character position 20 are (" & $ai[0] & "," & $ai[1] & ")")
Case 2
Report("2.The inter-character position at or nearest coordinates (" & $ai[0] & "," & $ai[1] & ")" & @CR & _
"is " & _GUICtrlRichEdit_GetCharPosFromXY($hRichEdit, $ai[0], $ai[1]))
GUICtrlSetState($btnNext, $GUI_DISABLE)
EndSwitch
EndSelect
WEnd
EndFunc ;==>Main
Func Report($sMsg)
GUICtrlSetData($lblMsg, $sMsg)
EndFunc ;==>Report