Jump to content

Go to a line number in edit control


WhyTea
 Share

Recommended Posts

You need to use GUICtrlSendMsg

GUICtrlSendMsg ($hEdit, $EM_LINESCROLL, 0, $nLine)
$nIndex = GUICtrlSendMsg ($hEdit, $EM_LINEINDEX, $nLine, 0)
$nLen = StringLen (ControlCommand ($hGUI, "", $hEdit, "GetLine", $nLine))
GUICtrlSendMsg ($hEdit, $EM_SETSEL, $nIndex, $nIndex + $nLen)

I haven't tried the code, but those are the messages you need. Read MSDN for details.

Mat

Link to comment
Share on other sites

You need to use GUICtrlSendMsg

GUICtrlSendMsg ($hEdit, $EM_LINESCROLL, 0, $nLine)
$nIndex = GUICtrlSendMsg ($hEdit, $EM_LINEINDEX, $nLine, 0)
$nLen = StringLen (ControlCommand ($hGUI, "", $hEdit, "GetLine", $nLine))
GUICtrlSendMsg ($hEdit, $EM_SETSEL, $nIndex, $nIndex + $nLen)

I haven't tried the code, but those are the messages you need. Read MSDN for details.

Mat

Thanks Matt. The code does go to the line number offset from the first line in the edit box, however the line of text is not highlighted. But that's good enough for I need to do.

/Why Tea

Link to comment
Share on other sites

Doesn't highlight it? Thats the bit I thought WOULD work :D lol.

Once you get to know how to use GUICtrlSendMsg you can do a lot more than you normally would be able to, so its good to read MSDN on it, I have got a similar thing to work before, and I think I used a similar code to that... I will look into it and post a better version soon!

Mat

Link to comment
Share on other sites

Doesn't highlight it? Thats the bit I thought WOULD work :D lol.

Once you get to know how to use GUICtrlSendMsg you can do a lot more than you normally would be able to, so its good to read MSDN on it, I have got a similar thing to work before, and I think I used a similar code to that... I will look into it and post a better version soon!

Mat

I'm looking forward to it. Thanks in advance!

/Why Tea

Link to comment
Share on other sites

Weird, testng it now and the old code works fine...

Run this and tell me what happens.

#include<editConstants.au3>

$hGUI = GUICreate ("Test", 200, 200)
$hEdit = GUICtrlCreateEdit ("", 2, 2, 196, 196)
For $i = 1 to 500
   GUICtrlSetData ($hEdit, @CRLF & "This is line: " & $i & ".", 1)
Next
GUISetstate ()
Sleep (1000)
_EditScrollAndHighliteLine ($hEdit, 250, $hGUI)
Sleep (5000)

Func _EditScrollAndHighliteLine ($hEdit, $nLine, $hGUI)
   GUICtrlSendMsg ($hEdit, $EM_LINESCROLL, 0, $nLine)
   $nIndex = GUICtrlSendMsg ($hEdit, $EM_LINEINDEX, $nLine, 0)
   $nLen = StringLen (ControlCommand ($hGUI, "", $hEdit, "GetLine", $nLine))
   GUICtrlSendMsg ($hEdit, $EM_SETSEL, $nIndex, $nIndex + $nLen)
EndFunc ; ==> _EditScrollAndHighliteLine

Mat

Link to comment
Share on other sites

Weird, testng it now and the old code works fine...

Run this and tell me what happens.

#include<editConstants.au3>

$hGUI = GUICreate ("Test", 200, 200)
$hEdit = GUICtrlCreateEdit ("", 2, 2, 196, 196)
For $i = 1 to 500
   GUICtrlSetData ($hEdit, @CRLF & "This is line: " & $i & ".", 1)
Next
GUISetstate ()
Sleep (1000)
_EditScrollAndHighliteLine ($hEdit, 250, $hGUI)
Sleep (5000)

Func _EditScrollAndHighliteLine ($hEdit, $nLine, $hGUI)
   GUICtrlSendMsg ($hEdit, $EM_LINESCROLL, 0, $nLine)
   $nIndex = GUICtrlSendMsg ($hEdit, $EM_LINEINDEX, $nLine, 0)
   $nLen = StringLen (ControlCommand ($hGUI, "", $hEdit, "GetLine", $nLine))
   GUICtrlSendMsg ($hEdit, $EM_SETSEL, $nIndex, $nIndex + $nLen)
EndFunc ; ==> _EditScrollAndHighliteLine

Mat

You do not need to use GUICtrlSendMsg(), all you need is present in the GUIEdit.au3 native AutoIt library.
Link to comment
Share on other sites

Weird, testng it now and the old code works fine...

Run this and tell me what happens.

#include<editConstants.au3>

$hGUI = GUICreate ("Test", 200, 200)
$hEdit = GUICtrlCreateEdit ("", 2, 2, 196, 196)
For $i = 1 to 500
   GUICtrlSetData ($hEdit, @CRLF & "This is line: " & $i & ".", 1)
Next
GUISetstate ()
Sleep (1000)
_EditScrollAndHighliteLine ($hEdit, 250, $hGUI)
Sleep (5000)

Func _EditScrollAndHighliteLine ($hEdit, $nLine, $hGUI)
   GUICtrlSendMsg ($hEdit, $EM_LINESCROLL, 0, $nLine)
   $nIndex = GUICtrlSendMsg ($hEdit, $EM_LINEINDEX, $nLine, 0)
   $nLen = StringLen (ControlCommand ($hGUI, "", $hEdit, "GetLine", $nLine))
   GUICtrlSendMsg ($hEdit, $EM_SETSEL, $nIndex, $nIndex + $nLen)
EndFunc ; ==> _EditScrollAndHighliteLine

Mat

Matt, your code work perfectly as it is. But when I called it from a button, it scrolled to the right line, but the line wasn't highlighted? Perhaps it's the highlighting color? When I manually selected the text it's the standard white on blue.

/Why Tea

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...