Jump to content
Sign in to follow this  
theAutoitSpammer

how to move caret to line/column in edit window

Recommended Posts

theAutoitSpammer

is there a function like _moveCaret($handle,"line","column") ???????

or a method to do so??

Share this post


Link to post
Share on other sites
Yashied

Share this post


Link to post
Share on other sites
theAutoitSpammer

_GUICtrlEdit_SetSel($hEdit, $iPos, $iPos)
_GUICtrlEdit_Scroll($hEdit, $SB_SCROLLCARET)

Thanks for the replay but this functions do not move the caret to

a line and column, they move the caret by caracter index.

Any other ideas??

Share this post


Link to post
Share on other sites
Yashied

Thanks for the replay but this functions do not move the caret to a line and column, they move the caret by caracter index.

Are you sure? You may use any text in the Edit control as one "string". I suggest you try it.

$Line1 & @CRLF & $Line2 & @CRLF & ...

Determine where the row and column it is not too difficult.

EDIT:

#Include <GUIConstantsEx.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>
#Include <WindowsConstants.au3>

$sFile = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\include\changelog.txt'
    
GUICreate('MyGUI', 400, 300)
$hEdit = GUICtrlCreateEdit('', 2, 2, 394, 268, BitOR($ES_WANTRETURN, $WS_VSCROLL))
GUISetState()

_GUICtrlEdit_SetText($hEdit, FileRead($sFile))
_GUICtrlEdit_SetSel($hEdit, 2217, 2217)
_GUICtrlEdit_Scroll($hEdit, $SB_SCROLLCARET)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by Yashied

Share this post


Link to post
Share on other sites
theAutoitSpammer

Thanks again

maybe I'm not making myself clear, I want to move the caret

to line 20 and column 5 for instance, on an equally spaced font.

how do I translate this into a number of characters since different lines have different amount of characters?.

your example adds all characters per line until it reaches 2217 then moves the caret there.

What I really want is to move the caret to a specific line and a specific column in autoit editor.

Any help is appreciated.

Edited by alram

Share this post


Link to post
Share on other sites
Yashied

I see people very lazy. :)

OK

#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>
#Include <WindowsConstants.au3>

$sFile = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\Include\ChangeLog.txt'

GUICreate('MyGUI', 400, 300)
$Edit = GUICtrlCreateEdit('', 10, 10, 380, 280, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL))
GUISetState()

_GUICtrlEdit_SetText($Edit, FileRead($sFile))
_GUICtrlEdit_SetPos($Edit, 37, 10)

Do
Until GUIGetMsg() = -3

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlEdit_SetPos
; Description....: Sets the caret to the specified line and column.
; Syntax.........: _GUICtrlEdit_SetPos ( $hWnd, $iLine [, $iColumn] )
; Parameters.....: $hWnd    - Handle or identifier (controlID) to the control.
;                  $iLine   - The zero-based index of the line on which must set the caret. If this parameter is (-1),
;                             the caret will be set on the last line.
;                  $iColumn - The zero-based index of the column on which must set the caret. If this parameter is (-1),
;                             the caret will be set at the end of the specified line. Default is 0.
; Return values..: Success  - 1.
;                  Failure  - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........: _GUICtrlEdit_Scroll(), _GUICtrlEdit_SetSel()
; Link...........: None
; Example........: Yes
; ===============================================================================================================================

Func _GUICtrlEdit_SetPos($hWnd, $iLine, $iColumn = 0)

    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return SetError(1, 0, 0)
        EndIf
    EndIf

    Local $Lenght, $Num = 0, $Count = _GUICtrlEdit_GetLineCount($hWnd)

    If $iLine > $Count - 1 Then
        $Num = _GUICtrlEdit_GetTextLen($hWnd)
    Else
        If $iLine < 0 Then
            $iLine = $Count - 1
        EndIf
        For $i = 0 To $iLine - 1
            $Num += _GUICtrlEdit_LineLength($hWnd, $i) + 2 ; + @CR + @LF
        Next
        $Lenght = _GUICtrlEdit_LineLength($hWnd, $iLine)
        If ($iColumn < 0) Or ($iColumn > $Lenght) Then
            $iColumn = $Lenght
        EndIf
        $Num += $iColumn
    EndIf
    _GUICtrlEdit_SetSel($hWnd, $Num, $Num)
    _GUICtrlEdit_Scroll($hWnd, $SB_SCROLLCARET)
    Return 1
EndFunc   ;==>_GUICtrlEdit_SetPos

Share this post


Link to post
Share on other sites
theAutoitSpammer

Thanks Yashied

I just saw your response because I was busy trying to solve the problem and since I only need

to goto line in SciTE, I came out with this (see below)

It works in any resolution, zoom and window size and position (at least so far)

I haven't try yours yet, but I'm almost sure it will work (not sure it will work in Scite).

I really appreciate your help.

By the way, you guys in Moscow need a lesson or two in English because I'm sure

you meant "busy" instead of "lazy" :)

local $Line = 20

_move_caret_SciTE($Line)

Func _move_caret_SciTE($moveL)

Local $L1, $L2, $Ydiff, $yMove

Opt("CaretCoordMode", 2)

ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "^{home}")

$L1 = WinGetCaretPos()

ControlSend("[CLASS:SciTEWindow]", "", "Scintilla1", "{down}")

$L2 = WinGetCaretPos()

$Ydiff = ($L2[1] - $L1[1])

$yMove = ($moveL - 1) * $Ydiff

Sleep(300)

ControlClick("[CLASS:SciTEWindow]", "", "Scintilla1", "left", 1, $L1[0], $yMove)

EndFunc ;==>_move_caret

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×