Andreik Posted July 15, 2009 Share Posted July 15, 2009 I need to get cursor position from an edit control to put on my status bar. I get line index with _GUICtrlEdit_LineFromChar($EDIT,-1) but nothing work for column index. I tried also some tricks with _GUICtrlEdit_SetSel(),_GUICtrlEdit_GetSel() without any result. Have anyone an idea? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
UberNuss Posted July 16, 2009 Share Posted July 16, 2009 There is a way to do this in AutoIt - I remember from a post I read back in May of this year. Das Häschen benutzt Radar. Link to comment Share on other sites More sharing options...
Malkey Posted July 16, 2009 Share Posted July 16, 2009 I need to get cursor position from an edit control to put on my status bar. I get line index with _GUICtrlEdit_LineFromChar($EDIT,-1) but nothing work for column index. I tried also some tricks with _GUICtrlEdit_SetSel(),_GUICtrlEdit_GetSel() without any result. Have anyone an idea? Try this. ; $iLineNum = ControlCommand("Edit Line From Char", "", $hEdit, "GetCurrentLine", "") $iCharPos = ControlCommand("Edit Line From Char", "", $hEdit, "GetCurrentCol", "") _GUICtrlStatusBar_SetText($StatusBar, "Line: " & $iLineNum & ", Col: " & $iCharPos) ; Link to comment Share on other sites More sharing options...
UberNuss Posted July 16, 2009 Share Posted July 16, 2009 Rasim used this line ...$iIndex = GUICtrlSendMsg($cCtrl, $EM_LINEINDEX, $iLine, 0)in this post: #616660 Das Häschen benutzt Radar. Link to comment Share on other sites More sharing options...
Andreik Posted July 16, 2009 Author Share Posted July 16, 2009 Just tried Malkey example and rasim example and doesn't work. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 16, 2009 Moderators Share Posted July 16, 2009 Andreik, You did not try hard enough - Malkey's code works perfectly! expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiEdit.au3> #Include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit("", 10, 10, 480, 380) For $i = 1 To 100 _GUICtrlEdit_AppendText($hEdit, "Line " & $i & @CRLF) Next GUICtrlCreateLabel("Line", 40, 420, 80, 20) $hLine_Num = GUICtrlCreateLabel("", 10, 420, 20, 20) GUICtrlCreateLabel("Column", 40, 450, 80, 20) $hColumn_Num = GUICtrlCreateLabel("", 10, 450, 20, 20) GUISetState() $iCurr_Line = 0 $iCurr_Col = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If _GUICtrlEdit_LineFromChar($hEdit) <> $iCurr_Line Then GUICtrlSetData($hLine_Num, _GUICtrlEdit_LineFromChar($hEdit) + 1) $iCurr_Line = _GUICtrlEdit_LineFromChar($hEdit) EndIf $iIndex = ControlCommand($hGUI, "", $hEdit, "getCurrentCol", "" ) If $iIndex <> $iCurr_Col Then GUICtrlSetData($hColumn_Num, $iIndex) $iCurr_Col = $iIndex EndIf WEnd 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  Link to comment Share on other sites More sharing options...
Andreik Posted July 16, 2009 Author Share Posted July 16, 2009 Yes, you are right. My fault was that I forgot to change window name in ControlCommand(); it was "Edit Line From Char". Sorry Malkey, and thank you and Melba. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 16, 2009 Moderators Share Posted July 16, 2009 (edited) Andreik, I have also found another scroll method (credit to Rasim) I have modifed his code a bit to match the other examples: expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiEdit.au3> #include <ScrollBarConstants.au3> $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit("", 10, 10, 480, 380) For $i = 1 To 100 _GUICtrlEdit_AppendText($hEdit, "Line " & $i & @CRLF) Next GUICtrlCreateLabel("Line", 40, 420, 80, 20) $hLine_Num = GUICtrlCreateLabel("", 10, 420, 20, 20) GUICtrlCreateLabel("Column", 40, 450, 80, 20) $hColumn_Num = GUICtrlCreateLabel("", 10, 450, 20, 20) $hInput = GUICtrlCreateInput("", 250, 410, 40, 20) $hButton = GUICtrlCreateButton("GoTo", 320, 410, 80, 30) GUISetState() $iCurr_Line = 0 $iCurr_Col = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $iNew_Line = Number(GUICtrlRead($hInput) - 1) GUICtrlSetData($hInput, "") _EditScroll($iNew_Line) _GUICtrlEdit_Scroll($hEdit, $SB_SCROLLCARET) EndSwitch If _GUICtrlEdit_LineFromChar($hEdit) <> $iCurr_Line Then GUICtrlSetData($hLine_Num, _GUICtrlEdit_LineFromChar($hEdit) + 1) $iCurr_Line = _GUICtrlEdit_LineFromChar($hEdit) EndIf $iIndex = ControlCommand($hGUI, "", $hEdit, "getCurrentCol", "" ) If $iIndex <> $iCurr_Col Then GUICtrlSetData($hColumn_Num, $iIndex) $iCurr_Col = $iIndex EndIf WEnd Func _EditScroll($iLine) Local $iIndex = GUICtrlSendMsg($hEdit, $EM_LINEINDEX, $iLine, 0) If $iIndex = -1 Then Return 0 GUICtrlSetState($hEdit, $GUI_FOCUS) GUICtrlSendMsg($hEdit, $EM_LINESCROLL, 0, $iLine) GUICtrlSendMsg($hEdit, $EM_SETSEL, $iIndex, $iIndex) EndFunc ;==>_TextScroll M23 Edit: better example script. Edited July 16, 2009 by Melba23  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  Link to comment Share on other sites More sharing options...
Andreik Posted July 16, 2009 Author Share Posted July 16, 2009 The exemple code work fine but just try to replace $cEdit = GUICtrlCreateEdit("", 10, 10, 280, 150) with $cEdit = _GUICtrlEdit_Create($hGUI,"", 10, 10, 280, 150) and in this case doesn't work. PS: I am tired, maybe I do something wrong. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Malkey Posted July 18, 2009 Share Posted July 18, 2009 The exemple code work fine but just try to replace $cEdit = GUICtrlCreateEdit("", 10, 10, 280, 150) with $cEdit = _GUICtrlEdit_Create($hGUI,"", 10, 10, 280, 150) and in this case doesn't work. PS: I am tired, maybe I do something wrong. Here is an example of getting the line and column position of the caret within a _GUICtrlEdit_Create() type edit control. expandcollapse popup; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiEdit.au3> #include <WinAPI.au3> ; used for Lo/Hi word #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> Opt('MustDeclareVars', 1) Global $hEdit, $StatusBar _Example1() Func _Example1() Local $hGUI, $aPartRightSide[2] = [378, -1] $hGUI = GUICreate("Edit Create", 400, 300) $hEdit = _GUICtrlEdit_Create($hGUI, FileRead("C:\Program Files\AutoIt3\SciTE\install.log"), 2, 2, 394, 268) $StatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide) GUISetState() Do StatusInfo() Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Example1 ;Line-Col Info Func StatusInfo() Local $iLineNum = _GUICtrlEdit_LineFromChar($hEdit, -1) Local $aCharPosNdx = _GUICtrlEdit_GetSel($hEdit) Local $iFrstCharOfLineNdx = _GUICtrlEdit_LineIndex($hEdit, -1) _GUICtrlStatusBar_SetText($StatusBar, "Ln: " & $iLineNum & ", Col: " & $aCharPosNdx[0] - $iFrstCharOfLineNdx) Return EndFunc ;==>StatusInfo ; Link to comment Share on other sites More sharing options...
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