Sign in to follow this  
Followers 0
JeyJ0

Get Cursor Position in Rich Edit

21 posts in this topic

Hey guys!

i Need to Get the current Cursor Position In a Rich edit. i tried _GUICtrlRichEdit_GetSel($hWnd), but it returns nothing :S

Does anybody know how to do this?


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Does this work for you?

#include <GuiRichEdit.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Main()

Func Main()
  Local Const $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
  
  Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_NOHIDESEL))
  
  Local Const $lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
  
  Local Const $btnGetPos = GUICtrlCreateButton("GetPos", 270, 310, 40, 30)
  
  GUISetState(@SW_SHOWNORMAL)

  Do
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
        Exit
        
      Case $btnGetPos
        Local $POINT = DllStructCreate($tagPoint)
         
        Local $dll_return = DllCall("User32.dll", "bool", "GetCaretPos", "ptr", DllStructGetPtr($POINT))
        
        If Not @error Then 
          local $coords = '(' & DllStructGetData($POINT, 1) & ',' & DllStructGetData($POINT, 2) & ')'
          _GUICtrlRichEdit_AppendText($hRichEdit, $coords)
        EndIf
    EndSwitch
  Until False
EndFunc

Oops, I misread.  I saw cursor and thought "caret".  Silly me.  And, also, this does not work the way you would expect.  When the cursor is at the top left, the coords are 1,1.  OK, that's right.  But then when I press the right arrow key once, the coords are then 8,1.  Weird!

Edit3: Wait, it isn't pixel coords dummy.  It's caret coords.  Sheesh.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You want to know the mouse position relative to the top-left corner of the Rich Edit control, correct?
 
1 - Set the mouse coord mode to be relative to the client area of the GUI: AutoItSetOption("MouseCoordMode", 2)

2 - Get the control's position.  You already know it if you created the GUI.  If it's a window you didn't create, use ControlGetPos() to get the position.  Note that for the first argument, "title", you can use a handle to the window if you have it.

3 - Get the mouse position: MouseGetPos()

4 - Subtract.  Something like: $RelativeMouseX = MouseGetPos(0) - $RichEditEdgeLeft

There you have it!   :)

EDIT - After I posted this, I think maybe you are looking for the caret position afterall...  You do want to use _GUICtrlRichEdit_GetSel() for that, but make sure the $handle you use is for the control, not the window.  The helpfile has a good working example for you.  If you're still having trouble, post your script (segment) please.

Edited by Artisan

Share this post


Link to post
Share on other sites

Sry, I think I used the wrong vocabulary... (I'm German) :ermm:

I mean the blinky "|" in a Text-Edit. I hope you understand.

(Is that caret?)


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

JeyJ0,

Yes. The cursor is moved by the mouse and the caret shows where text will be inserted. :)

And _GUICtrlRichEdit_GetSel should be the function to use to get its position. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you! :)

I know, but how should I do that, because I tried it and the return value was empty :unsure:


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

JeyJ0,

Did you do as Artisan suggested above and use the RichEdit handle when calling the function? :huh:

Perhaps you could post the code you tried - see here how to do it. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

#include <Array.au3>
#include <GuiRichEdit.au3>
[...]
$cPos = _GUICtrlRichEdit_GetSel($Edit)
_ArrayDisplay($cPos) ; nothing, script crashes...
$cPos = _GUICtrlRichEdit_GetCharPosFromXY($Edit, $cPos[0], $cPos[1])
_GUICtrlRichEdit_GotoCharPos($Edit, $cPos)

every other interaction with $Edit works, so that isn't the problem...

Edited by JeyJ0

[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

JeyJ0,

 

_ArrayDisplay($cPos) ; nothing, script crashes...
Firstly, always add errorchecking before trying to access any array. That is a must. ;)

Secondly, I have used the function and it worked without problem. Can you provide some runnable code that illustrates the same error? Then we might spot something elsewhere. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Static $operatoren
Static $APIs
Static $keywords
Static $lua
Static $strings
_FileReadToArray(@ScriptDir & "\resources\operatoren.txt", $operatoren)
_FileReadToArray(@ScriptDir & "\resources\apis.txt", $APIs)
_FileReadToArray(@ScriptDir & "\resources\keywords.txt", $keywords)
_FileReadToArray(@ScriptDir & "\resources\lua.txt", $lua)
_FileReadToArray(@ScriptDir & "\resources\strings.txt", $strings)

; #FUNCTION# ====================================================================================================================
; Name...........: startup
; Description ...: Lässt das Programm laufen und fängt die GUI-Messages ab.
; Syntax.........: startup()
; Author ........: Jey J0
; ===============================================================================================================================
Func startup()
   _createGUI()
   While 1
      $msg = GUIGetMsg()
      
      Switch $msg
         Case $GUI_EVENT_CLOSE
            _Exit()
         Case $GUI_EVENT_MAXIMIZE
            _aktGUI()
         Case $GUI_EVENT_RESIZED
            _aktGUI()
         Case $_highlight
            _highlight()
      EndSwitch
   WEnd
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _highlight
; Description ...: Highlightet den Text im RichEdit.
; Syntax.........: _highlight()
; Author ........: Jey J0
; ===============================================================================================================================
Func _highlight()
   Local $editText = _GUICtrlRichEdit_GetText($Edit)
   Local $cPos = _GUICtrlRichEdit_GetSel($Edit)
   _ArrayDisplay($cPos)
   $cPos = _GUICtrlRichEdit_GetCharPosFromXY($Edit, $cPos[0], $cPos[1])
   ; Keywords: bold, black, italic
   For $i=1 To $keywords[0]
      Local $pos = -1
      Local $count = 1
      While $pos<>0
         $pos = StringInStr($editText, $keywords[$i], 1, $count)
         Local $wordLength = StringLen($keywords[$i])
         Local $folgeZeichen = StringTrimLeft($editText, $pos - 1 + $wordLength)
         $folgeZeichen = StringTrimRight($folgeZeichen, StringLen($folgeZeichen) - 1)
         If $pos > 0 And _folgeZeichenOK($folgeZeichen, "keyword") Then
            $count = $count + 1
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1 + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+bo", True)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+it", True)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos + $wordLength, $pos + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-it", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-it", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         ElseIf $pos > 0 And Not _folgeZeichenOk($folgeZeichen, "keyword") Then
            $pos = 0
         EndIf
      WEnd
   Next
   ; APIs: bold, black
   For $i=1 To $APIs[0]
      Local $pos = -1
      Local $count = 1
      While $pos<>0
         $pos = StringInStr($editText, $APIs[$i], 1, $count)
         Local $wordLength = StringLen($APIs[$i])
         Local $folgeZeichen = StringTrimLeft($editText, $pos - 1 + $wordLength)
         $folgeZeichen = StringTrimRight($folgeZeichen, StringLen($folgeZeichen) - 1)
         If $pos > 0 And _folgeZeichenOK($folgeZeichen, "api") Then
            $count = $count + 1
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1 + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+bo", True)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos + $wordLength, $pos + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         ElseIf $pos > 0 And Not _folgeZeichenOk($folgeZeichen, "api") Then
            $pos = 0
         EndIf
      WEnd
   Next
   ; Operatoren: bold, orange
   For $i=1 To $operatoren[0]
      Local $pos = -1
      Local $count = 1
      While $pos<>0
         $pos = StringInStr($editText, $operatoren[$i], 1, $count)
         Local $wordLength = StringLen($operatoren[$i])
         Local $folgeZeichen = StringTrimLeft($editText, $pos - 1 + $wordLength)
         $folgeZeichen = StringTrimRight($folgeZeichen, StringLen($folgeZeichen) - 1)
         If $pos > 0 Then
            $count = $count + 1
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1 + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+bo", True)
            _GUICtrlRichEdit_SetCharColor($Edit, "ff8000")
            _GUICtrlRichEdit_SetSel($Edit, $pos + $wordLength, $pos + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         EndIf
      WEnd
   Next
   ; lua: bold, italic, darkblue
   For $i=1 To $lua[0]
      Local $pos = -1
      Local $count = 1
      While $pos<>0
         $pos = StringInStr($editText, $lua[$i], 1, $count)
         Local $wordLength = StringLen($lua[$i])
         Local $folgeZeichen = StringTrimLeft($editText, $pos - 1 + $wordLength)
         $folgeZeichen = StringTrimRight($folgeZeichen, StringLen($folgeZeichen) - 1)
         If $pos > 0 And _folgeZeichenOK($folgeZeichen, "lua") Then
            $count = $count + 1
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1 + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+bo", True)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "+it", True)
            _GUICtrlRichEdit_SetCharColor($Edit, "0000ff")
            _GUICtrlRichEdit_SetSel($Edit, $pos + $wordLength, $pos + $wordLength)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-it", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
            _GUICtrlRichEdit_SetSel($Edit, $pos - 1, $pos - 1)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-bo", False)
            _GUICtrlRichEdit_SetCharAttributes($Edit, "-it", False)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         EndIf
      WEnd
   Next
   ; Strings: lightgray
   For $i=1 To $strings[0]
      Local $pos1 = -1
      Local $pos2 = -1
      Local $count = 1
      While $pos2<>-2 And $pos2<>-2
         $pos1 = StringInStr($editText, $strings[$i], 1, $count)
         $count = $count + 1
         $pos2 = StringInStr($editText, $strings[$i], 1, $count)
         $count = $count + 1
         If $pos1 = 0 And $pos2 = 0 Then
            $pos2 = -2
         ElseIf $pos1 <> 0 And $pos2 = 0 Then
            _GUICtrlRichEdit_SetSel($Edit, $pos1, -1)
         ElseIf $pos1 <> 0 And $pos2 <> 0 Then
            _GUICtrlRichEdit_SetSel($Edit, $pos1, $pos2)
         EndIf
         _GUICtrlRichEdit_SetCharColor($Edit, "aaaaaa")
         If $pos1 <> 0 Then
            _GUICtrlRichEdit_SetSel($Edit, $pos1, $pos1)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         EndIf
         If $pos2 <> 0 Then
            _GUICtrlRichEdit_SetSel($Edit, $pos2+1, $pos2+1)
            _GUICtrlRichEdit_SetCharColor($Edit, "000000")
         EndIf
      WEnd
   Next
   _GUICtrlRichEdit_Deselect($Edit)
   _GUICtrlRichEdit_GotoCharPos($Edit, $cPos)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _folgeZeichenOK
; Description ...: Fragt ab, ob das Folgezeichen des Keywords ok ist.
; Syntax.........: _folgeZeichenOK($zeichen, $keywordArt)
; Params.........: $zeichen - Das zu testende Zeichen
;                  $keywordArt - Die Art des Wortes vor dem Zeichen.
; Return.........: True - Zeichen ist ok
;                  False - Zeichen ist nicht ok
;                  nil - $keywordArt gibt es nicht
; Author ........: Jey J0
; ===============================================================================================================================
Func _folgeZeichenOK($z, $art)
   If $art = "keyword" Then
      If $z == " " Or $z == "(" Or $z == @CR Or $z == @CRLF Or $z == @LF Then
         Return True
      Else
         Return False
      EndIf
   ElseIf $art = "api" Then
      If $z == "." Then
         Return True
      Else
         Return False
      EndIf
   ElseIf $art = "lua" Then
      If $z == " " Then
         Return True
      Else
         Return False
      EndIf
   Else
      Return
   EndIf
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _createGUI
; Description ...: Erstellt das Hauptfenster
; Syntax.........: _createGUI()
; Author ........: Jey J0
; ===============================================================================================================================
Func _createGUI()
   Opt("CaretCoordMode", 2)
   Opt("GUICloseOnESC", 0)
   GUISetBkColor(0xAAAAAA)
   
   Global $GUI = GUICreate("CC IDE", @DesktopWidth-100, @DesktopHeight-100, 50, 50, $WS_MAXIMIZEBOX)
   Global $GUIClientSize = WinGetClientSize("CC IDE")
   
   Global $TreeView = GUICtrlCreateTreeView(10, 10, $GUIClientSize[0]/100*20-10, $GUIClientSize[1]-40)
   
   Global $Edit = _GUICtrlRichEdit_Create($GUI, "", $GUIClientSize[0]/100*20+10, 10, $GUIClientSize[0]/100*80-20, $GUIClientSize[1]-40, _ 
               BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))
   _GUICtrlRichEdit_SetEventMask($Edit, $ENM_CHANGE)
   GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
               
   Global $Funktionen = GUICtrlCreateMenu("Funktionen")
   Global $_highlight = GUICtrlCreateMenuItem("_highlight()", $Funktionen)
   
   GUISetState(1)
EndFunc

variables and comments are german!

i think thats what you wanted. It's my code - or better the code that depends...

Edit: i forgot the includes, but they are all ok!^^

Edited by JeyJ0

[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

JeyJ0,

I said "runnable" - that code has more errors than I can count! :o

Declare Global variables at the top of your script - not within functions. That should solve a lot of the problems as half of the time Autoit has no idea what any of the variables are - so it is hardly suprising that I get lots of:

warning: $Edit: possibly used before declaration
in your _highlightfunction. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hard to tell if the call to startup is missing in just this code or in the code that runs on your system. Basically, if it doesn't run on your system then it won't run on ours.

Avoid declaring global variables inside of functions.

Everything that Melba23 said. ^^^^^^^^^^^^^^^

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

Sorry, I thought it Works like that... (forgit startup())Tomorrow I'll Post the while Code!

I could Out the global variables at the Top too, but it's more comfortable like that,i think. I only call the function once.


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

JeyJO, you waste our time and yours. please post a reproducable code and especially the gui, - or leave it. we are not able to guess. when we could see the code, we would fix it within a minute, believe me.

i see from your coding that you are quite ambitious and not fooling around, so please use this forum with intelligence and common sense.

E.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Edano,

That was uncalled for - particularly as you have not yet contributed to this thread, so none of your time has been wasted. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@Edano: I don't think that you'd fix it within a minute because there's so much code around that you have to search a very long time to find where you have to search... Yesterday I only had little time, so I couldn't concentrate much.

I hope this is all you need:

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Func _caretSamePos()
   ; After this function the caret should be at the same Position as before! ================================================================================
   Local $editText = _GUICtrlRichEdit_GetText($Edit)
   Local $cPos = _GUICtrlRichEdit_GetSel($Edit)
   $cPos = _GUICtrlRichEdit_GetCharPosFromXY($Edit, $cPos[0], $cPos[1])
   
   ; There is some code inbetween, but it doesn't matter...
   ; To have something that does something i'll do this:
   _GUICtrlRichEdit_GotoCharPos($Edit, 6)
   
   ; back to "normal" stuff^^
   _GUICtrlRichEdit_GotoCharPos($Edit, $cPos)
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
   If _WinAPI_HiWord($wParam) = $EN_CHANGE Then _caretSamePos()
EndFunc
   
; create the GUI
   Opt("CaretCoordMode", 2)
   Opt("GUICloseOnESC", 0)
   GUISetBkColor(0xAAAAAA)
   
   Global $GUI = GUICreate("CC IDE", @DesktopWidth-100, @DesktopHeight-100, 50, 50, $WS_MAXIMIZEBOX)
   Global $GUIClientSize = WinGetClientSize("CC IDE")
      
   Global $Edit = _GUICtrlRichEdit_Create($GUI, "This is a little text to show you, that it can be here^^"&@CR&"Please type something else in here!", $GUIClientSize[0]/100*20+10, 10, $GUIClientSize[0]/100*80-20, $GUIClientSize[1]-40, _ 
               BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))
   _GUICtrlRichEdit_SetEventMask($Edit, $ENM_CHANGE)
   GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
   
   GUISetState(1)
   
   While 1
      $msg = GUIGetMsg()
      
      Switch $msg
         Case $GUI_EVENT_CLOSE
            Exit
      EndSwitch
   WEnd

If there are questions left, feel free to ask!^^

PS: This code works for me, except the part that doesn't work! I mean I get no errors... But it doesn't work as it should.

Edited by JeyJ0

[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

Does this work for you?

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

; create the GUI
Opt("CaretCoordMode", 2)

Opt("GUICloseOnESC", 0)

GUISetBkColor(0xAAAAAA)

Global $GUI = GUICreate("CC IDE", @DesktopWidth - 700, @DesktopHeight - 700, 50, 50, $WS_MAXIMIZEBOX)

Global $GUIClientSize = WinGetClientSize("CC IDE")

Global $Edit = _GUICtrlRichEdit_Create($GUI, "This is a little text to show you, that it can be here^^" & @CR & _ 
                                             "Please type something else in here!", _
                                             $GUIClientSize[0] / 100 * 20 + 10, _
                                             10, _
                                             $GUIClientSize[0] / 100 * 80 - 20, _
                                             $GUIClientSize[1] - 40, _
                                             BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))

_GUICtrlRichEdit_SetEventMask($Edit, $ENM_CHANGE)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOWNORMAL)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _caretSamePos()
    ; After this function the caret should be at the same Position as before! 
    Local $editText = _GUICtrlRichEdit_GetText($Edit)
    
    Local $cPos = _GUICtrlRichEdit_GetSel($Edit)
    ConsoleWrite("_GUICtrlRichEdit_GetSel: (" & $cPos[0] & ',' & $cPos[1] & ')' & @CRLF)
            
;~  $cPos = _GUICtrlRichEdit_GetCharPosFromXY($Edit, $cPos[0], $cPos[1])
;~  ConsoleWrite("_GUICtrlRichEdit_GetCharPosFromXY: " & $cPos & @crlf) 

    ; back to "normal" stuff^^
    _GUICtrlRichEdit_SetSel($Edit, $cPos[0], $cPos[1])
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    If _WinAPI_HiWord($wParam) = $EN_CHANGE Then _caretSamePos()
EndFunc

Share this post


Link to post
Share on other sites

Will try it tomorrow, but that should work. :)


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

Share this post


Link to post
Share on other sites

thx, it works! ;)

(Why doesn't the other one work?!)


[font="'courier new', courier, monospace;"]--------------------------------------------------------[/font]

[font="'courier new', courier, monospace;"]Sorry for bad english, I'm from Germany...[/font]

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  
Followers 0