Sign in to follow this  
Followers 0
WhyTea

Go to a line number in edit control

10 posts in this topic

I have created an edit control for a file to be loaded, is there a way to jump to a specific line and highlight it?

/Why Tea

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

oh year!! completely forgot about that! Although in my defence, that UDF does just use SendMessage to get the job done...

Thats a much easier way to do it, but its a bit less exciting, don't you think? :D

Mat

Share this post


Link to post
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

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