WinGetCaretPos

首页  后退  前进

WinGetCaretPos
down2

WinGetCaretPos

返回当前窗口插入符的坐标.

 

WinGetCaretPos ( )

返回值

成功:

返回含有下列信息的 2 元素数组:

   $aArray[0] = X 坐标

   $aArray[1] = Y 坐标

失败:

设置 @error 为 非 0 值.

备注

若设置 CaretCoordMode 使用绝对位置, WinGetCaretPos 可能不会返回多文档界面(MDI) 插入符的精确坐标值.

解决方法请参考下面的示例. 注意:某些应用程序无视插入符的位置, 仅报告静态坐标!

 

函数示例

Local $aCaretPos = WinGetCaretPos()
If Not @error Then
    ToolTip("First Method", $aCaretPos[0], $aCaretPos[1])
EndIf
Sleep(2000)
$aCaretPos = _WinGetCaretPos()
If Not @error Then
    ToolTip("Second Method", $aCaretPos[0], $aCaretPos[1])
EndIf
Sleep(2000)
; A more reliable method to retrieve the caret coordinates in MDI text editors.
Func _WinGetCaretPos()
    Local $iXAdjust = 5
    Local $iYAdjust = 40
    Local $iOpt = Opt("CaretCoordMode", 0) ; Set "CaretCoordMode" to relative mode and store the previous option.
    Local $aGetCaretPos = WinGetCaretPos() ; Retrieve the relative caret coordinates.
    Local $aGetPos = WinGetPos("[ACTIVE]") ; Retrieve the position as well as height and width of the active window.
    Local $sControl = ControlGetFocus("[ACTIVE]") ; Retrieve the control name that has keyboard focus.
    Local $aControlPos = ControlGetPos("[ACTIVE]", "", $sControl) ; Retrieve the position as well as the size of the control.
    $iOpt = Opt("CaretCoordMode", $iOpt) ; Reset "CaretCoordMode" to the previous option.
    Local $aReturn[2] = [0, 0] ; Create an array to store the x, y position.
    If IsArray($aGetCaretPos) And IsArray($aGetPos) And IsArray($aControlPos) Then
        $aReturn[0] = $aGetCaretPos[0] + $aGetPos[0] + $aControlPos[0] + $iXAdjust
        $aReturn[1] = $aGetCaretPos[1] + $aGetPos[1] + $aControlPos[1] + $iYAdjust
        Return $aReturn ; Return the array.
    Else
        Return SetError(1, 0, $aReturn) ; Return the array and set @error to 1.
    EndIf
EndFunc   ;==>_WinGetCaretPos

----------------------------------------

 

该函数可以通过命令调用 exect

参见:

CaretCoordMode (Опция)

例子
copy

exect=$var_array=WinGetCaretPos()||_ViewValues($var_array) ;;获取活动窗口的光标坐标

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru