Sign in to follow this  
Followers 0
ds34

"Find" in RichtTextEdit

9 posts in this topic

I have a RichTextEdit and use it as a log application. I would like to add a "find/ find next" function for this log.

Anyone of you who has an idea of how-to or even sample implementation?

Cheers!

Share this post


Link to post
Share on other sites



ds34,

Here is a example using _GUICtrlRichEdit_FindText - which is designed to do just what you want: :)

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

Global $lblMsg, $hRichEdit

Main()

Func Main()

    Local $sSearchTerm = "another"
    Local $iSearchStart = 0

    Local $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
    Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a line." & @CRLF & "And this is another line." & _
            @CRLF & "And yet another line.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    Local $hFind_Button = GUICtrlCreateButton("Find", 230, 310, 80, 30)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
            Case $hFind_Button
                If GUICtrlRead($hFind_Button) = "Find" Then
                    GUICtrlSetData($hFind_Button, "Again")
                    _GUICtrlRichEdit_SetSel($hRichEdit, $iSearchStart, $iSearchStart)
                    $iIndex = _GUICtrlRichEdit_FindText($hRichEdit, $sSearchTerm)
                    _GUICtrlRichEdit_SetSel($hRichEdit, $iIndex, $iIndex + StringLen($sSearchTerm))
                    $iSearchStart = $iIndex + StringLen($sSearchTerm)
                Else
                    GUICtrlSetState($hFind_Button, $GUI_DISABLE)
                    _GUICtrlRichEdit_SetSel($hRichEdit, $iSearchStart, $iSearchStart)
                    $iIndex = _GUICtrlRichEdit_FindText($hRichEdit, $sSearchTerm)
                    _GUICtrlRichEdit_SetSel($hRichEdit, $iIndex, $iIndex + StringLen($sSearchTerm))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Main

I hope that helps. :(

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

Thanks,

seems I should have made a move to the "new" GUIRichEdit.

However, this is not feasible, since the old GUIRichEdit I am using is way faster and this performance is critical in my case (lots of small, differently formatted text pieces to be appended to the RichTextEdit every second).

I will check the _GUICtrlRichEdit_FindText() if I can find a way to reuse/adapt this to the my version of "a" UDF (I do not even know the real version of this, since its an unversioned file from Gary Frost/Yoan Roblet I took from the forum ages ago).

I know it misses lots of finetuning/features (i.e. resizing support) compared to the new UDF, but again, the performance counts here.

Thanks again!

Daniel

Share this post


Link to post
Share on other sites

I tried to run this code directly, but get "ERROR: _GUICtrlRichEdit_FindText(): undefined function."

I also get the "undefined function" error when trying to use _GUICtrlRichEdit_FindTextEx and _GUICtrlRichEdit_GetTextRange in my own code. The functions are recognized by AutoIt's CallTips, leading me to think they are found. Yet other RichEdit functions work fine.

I can't figure out what the problem is. Any idea?

ds34,

Here is a example using _GUICtrlRichEdit_FindText - which is designed to do just what you want: :x

<snip>

Share this post


Link to post
Share on other sites

DickG ,

Any idea?

Which AutoIt version are you using? :x

The 2 additional commands you mention (_GUICtrlRichEdit_FindTextEx and _GUICtrlRichEdit_GetTextRange) are not in the current release - add the fact that you cannot use _GUICtrlRichEdit_FindText (which is) and it looks very much as though you are a little behind on the update front. :P

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

I'm using 3.3.0.0. So you're probably right about that being the reason.

I've been putting off updating because I might have to spend time debugging those that break due to the changes. So I'll just have to bite the bullet and update.

DickG ,

Which AutoIt version are you using? :x

The 2 additional commands you mention (_GUICtrlRichEdit_FindTextEx and _GUICtrlRichEdit_GetTextRange) are not in the current release - add the fact that you cannot use _GUICtrlRichEdit_FindText (which is) and it looks very much as though you are a little behind on the update front. :P

M23

Share this post


Link to post
Share on other sites

DickG,

Good luck to you with the updating - it will be worth it. :x

I would wait until after Xmas though, or your dinner is likely to be overcooked and you might miss Santa! :P

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

I bit the bullet and updated all my scripts. Luckily, not that much needed changing. All went well.

But now AutoIt can't find these commands:

o _GUICtrlRichEdit_GetBold

o _GUICtrlRichEdit_SetBold

o _GUICtrlRichEdit_SetOLECallback

o $ES_SUNKEN as parameter to _GUICtrlRichEdit_Create

I searched the forum and the Help file, but can't find anything about them. Were they deleted? Is there a replacement or workaround?

DickG,

Good luck to you with the updating - it will be worth it. :x

I would wait until after Xmas though, or your dinner is likely to be overcooked and you might miss Santa! :P

M23

Share this post


Link to post
Share on other sites

OK, I did more digging and discovered how to handle the bold (_GetCharAttributes and _SetCharAttributes). No problem on $ES_SUNKEN: I just deleted that.

The only problem I have is not being able to unbold text after bolding it.

I'm using _GUICtrlRichEdit_SetCharAttributes($hwnd, "+bo", True) to make it bold and _GUICtrlRichEdit_SetCharAttributes($hwnd, "-bo", True) to try to unbold it, but "-bo" doesn't do it.

Well, anyway, hope you have a great Christmas and New Year, Melba. And thanks for your help.

Dick

I bit the bullet and updated all my scripts. Luckily, not that much needed changing. All went well.

But now AutoIt can't find these commands:

o _GUICtrlRichEdit_GetBold

o _GUICtrlRichEdit_SetBold

o _GUICtrlRichEdit_SetOLECallback

o $ES_SUNKEN as parameter to _GUICtrlRichEdit_Create

I searched the forum and the Help file, but can't find anything about them. Were they deleted? Is there a replacement or workaround?

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