tito Posted January 11, 2011 Posted January 11, 2011 (edited) Hi, I'm trying to retrieve to cursor position in a multiline edit ctrl. When edit ctrl is saved, the cursor position should also be saved. If user reopens the edit ctrl, (using a fileread/replace content) , I try to put the cursor back where it was. Now I autoscroll to the last line using: $iLen = _GUICtrlEdit_GetLineCount($GUINotepad) _GUICtrlEdit_LineScroll($GUINotepad, 1, $iLen) but this isn't what I'm trying to do... I need something like '_GUICtrlEdit_GetCursorPos()' Any ideas? Edited January 11, 2011 by tito
Moderators Melba23 Posted January 11, 2011 Moderators Posted January 11, 2011 tito, Any ideas?Yes! expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #Include <GuiEdit.au3> Global $aLocation[2] = [0, 0] $sText = "This is a long pice of text which should require wrapping in the edit control - " & _ "which is provided by the combination of $ES_WANTRETURN and $ES_MULTILINE styles" $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit($sText, 10, 10, 200, 200, BitOr($ES_WANTRETURN, $ES_MULTILINE)) $hButton_Locate = GUICtrlCreateButton("Locate", 10, 300, 80, 30) $hButton_Reset = GUICtrlCreateButton("Reset", 10, 350, 80, 30) $hButton_Relocate = GUICtrlCreateButton("Relocate", 10, 400, 80, 30) $hLabel_Line = GUICtrlCreateLabel("Line: ", 100, 300, 100, 20) $hLabel_Col = GUICtrlCreateLabel("Col: ", 200, 300, 100, 20) GUISetState() ; Set cursor to start _GUICtrlEdit_SetSel($hEdit, 0, 0) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_Locate ; Show and save current position GUICtrlSetData($hLabel_Line, "Line: " & ControlCommand($hGUI, "", $hEdit, "GetCurrentLine", "")) GUICtrlSetData($hLabel_Col, "Col: " & ControlCommand($hGUI, "", $hEdit, "GetCurrentCol", "")) ; Get current position in usable form $aLocation = _GUICtrlEdit_GetSel($hEdit) GUICtrlSetState($hEdit, $GUI_FOCUS) Case $hButton_Reset ; Reset cursor to start GUICtrlSetState($hEdit, $GUI_FOCUS) _GUICtrlEdit_SetSel($hEdit, 0, 0) Case $hButton_Relocate ; Relocate cursor to stored position GUICtrlSetState($hEdit, $GUI_FOCUS) _GUICtrlEdit_SetSel($hEdit, $aLocation[0], $aLocation[1]) EndSwitch WEnd All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Yashied Posted January 11, 2011 Posted January 11, 2011 Addition. expandcollapse popup#Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> #Include <WindowsConstants.au3> $sFile = RegRead('HKLM\SOFTWARE\AutoIt v3\AutoIt', 'InstallDir') & '\Include\Array.au3' 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, 5, 18) 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 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
tito Posted January 11, 2011 Author Posted January 11, 2011 All clear? M23Works perfectlyThank you thank you thank you Now, Any idea how I can correctly scroll to the selected cursor position?
Moderators Melba23 Posted January 11, 2011 Moderators Posted January 11, 2011 tito,Would Sir like fries with that! Look at _GUICtrlEdit_Scroll using the $SB_SCROLLCARET parameter in the Help file.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
tito Posted January 11, 2011 Author Posted January 11, 2011 Would Sir like fries with that! No, thx though Dim $notepad_scroll_position[2] $notepad_scroll_position[0] = 0 $notepad_scroll_position[1] = 0 (used if no scroll position previously saved) $notepad_scroll_position = _GUICtrlEdit_GetSel($GUINotepad) => _GUICtrlEdit_SetSel($GUINotepad, $notepad_scroll_position[0], $notepad_scroll_position[1]) _GUICtrlEdit_Scroll($GUINotepad, $SB_SCROLLCARET)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now