- Сообщения
- 5,379
- Репутация
- 2,724
Функция устанавливает курсор (каретку) в указанную позицию в элементах Edit. Местоположение курсора задается номером строки (0 - первая строка) и номером символа (0 - первый символ) в этой строке.
Код:
#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