Jump to content

Find function?


Recommended Posts

Hello everyone, I am wondering if there is any sort of find function that comes with a GUI (like the Fileopendialog is a GUI that returns a string), is there one that already has the find dialog made and already functions fully? I would prefer an autoIT native function if possible, however, if there isnt one, I will use a UDF, if one exists.

Thanks.

Link to comment
Share on other sites

If you mean Find/Replace dialogs for edits then yes, but not natively.

Try mess around with this and if not I'll dig up a very old script of mine for you that uses it.

My advice on implementing it is to check how other common dialogs are done in the UDFs and on the forums.

As an alternative, an InputBox will do most of what you want it to. Sure it wopn't really look the same, but it's a lot easier.

Link to comment
Share on other sites

There are very few GUIs provided for you with AutoIt. FileSelectFolder is one, but you generally have to make your own. There are all kinds of UDFs that have been created for finding things, and it's quite likely that one will suit your purpose. What exactly are you trying to find?

Link to comment
Share on other sites

First up, there is actually a function _GUICtrlEdit_Find which does exactly this using an AutoIt GUI. IMO it looks crap, but it's an include and a function call, so it's very easy to do.

But I like the windows one that you see in notepad, here is the most basic example I could write. It doesn't actually do the search/replace, you have to do that yourself. Richedits make this easy with a function that does it all for you, but edits don't.

#include<WinAPI.au3>
#include <RichEditConstants.au3>

; A few constants you need that aren't included with AutoIt
Global Const $FR_FINDNEXT = 0x00000008
Global Const $FR_REPLACE = 0x00000010
Global Const $FR_REPLACEALL = 0x00000020
Global Const $FR_DIALOGTERM = 0x00000040
Global Const $FR_DIALOGMESSAGE = "commdlg_FindReplace"

; And a struct:
Global Const $tagFINDREPLACE = "dword lStructSize; hwnd hwndOwner; hwnd hInstance; dword Flags; ptr lpstrFindWhat; ptr lpstrReplaceWith; ushort wFindWhatLen; ushort wReplaceWithLen; " & _
        "ptr lCustData; ptr lpfnHook; ptr lpTemplateName;"

; First we initialise the struct we need for the find/replace dialog
Global $tFINDREPLACE = DllStructCreate($tagFINDREPLACE)
Global $tFindWhat = DllStructCreate("char Find[256]")
Global $tReplaceWith = DllStructCreate("char Replace[256]")
DllStructSetData($tFINDREPLACE, "hInstance", _WinAPI_GetModuleHandle(""))
DllStructSetData($tFINDREPLACE, "Flags", $FR_DOWN)
DllStructSetData($tFINDREPLACE, "lpstrFindWhat", DllStructGetPtr($tFindWhat))
DllStructSetData($tFINDREPLACE, "lpstrReplaceWith", DllStructGetPtr($tReplaceWith))
DllStructSetData($tFINDREPLACE, "wFindWhatLen", 255)
DllStructSetData($tFINDREPLACE, "wReplaceWithLen", 255)
DllStructSetData($tFINDREPLACE, "lCustData", 0)
DllStructSetData($tFINDREPLACE, "lpfnhook", 0)
DllStructSetData($tFINDREPLACE, "lpTemplateName", 0)
DllStructSetData($tFINDREPLACE, "lStructSize", DllStructGetSize($tFINDREPLACE))


; Create an example GUI
Global $hGUI, $hEdit, $GUI_Edit
Global $hSearchMenu, $hSearchMenu_Find, $hSearchMenu_Replace

$hGUI = GUICreate("Example for Find/replace dialog", 500, 400)
DllStructSetData($tFINDREPLACE, "hwndOwner", $hGUI)

$hSearchMenu = GUICtrlCreateMenu("&Search")
$hSearchMenu_Find = GUICtrlCreateMenuItem("&Find..." & @TAB & "Ctrl+F", $hSearchMenu)
$hSearchMenu_Replace = GUICtrlCreateMenuItem("&Replace..." & @TAB & "Ctrl+H", $hSearchMenu)

$hEdit = GUICtrlCreateEdit("", 2, 2, 496, 396)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case $hSearchMenu_Find
            ; Find clicked. We default to selected text unless it includes newlines.
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "FindText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
        Case $hSearchMenu_Replace
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            ; I like to default the replace to the clipboard text.
            Local $sReplace = ClipGet()
            If StringInStr($sReplace, @CR) Or StringInStr($sReplace, @LF) Then
                $sReplace = ""
            Else
                $sReplace = StringReplace($sReplace, @TAB, " ")
            EndIf
            DllStructSetData($tReplaceWith, "Replace", $sReplace)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "ReplaceText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
    EndSwitch
WEnd

Func __FindReplace_Notify($hWnd, $iMsgId, $wParam, $lParam)
    #forceref $hWnd, $iMsgId, $wParam, $lParam
    Local $iFlags = DllStructGetData($tFINDREPLACE, "Flags"), _
            $fDir = BitAND($iFlags, $FR_DOWN) <> 0, _
            $fMatchCase = BitAND($iFlags, $FR_MATCHCASE) <> 0, _
            $fWholeWord = BitAND($iFlags, $FR_MATCHCASE) <> 0, _
            $iBehavior = BitOR(BitAND($iFlags, $FR_MATCHALEFHAMZA), BitAND($iFlags, $FR_MATCHDIAC), BitAND($iFlags, $FR_MATCHKASHIDA)), _
            $sFind = DllStructGetData($tFindWhat, 1), $sReplace = DllStructGetData($tReplaceWith, 1)
    Select
        Case BitAND($iFlags, $FR_FINDNEXT)
            ConsoleWrite("FIND '" & $sFind & "'" & @CRLF)
        Case BitAND($iFlags, $FR_REPLACE)
            ConsoleWrite("REPLACE" & @CRLF)
        Case BitAND($iFlags, $FR_REPLACEALL)
            ConsoleWrite("REPLACEALL" & @CRLF)
        Case BitAND($iFlags, $FR_DIALOGTERM)
            ConsoleWrite("DIALOGTERM" & @CRLF)
            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "")
    EndSelect
EndFunc   ;==>__FindReplace_Notify
Edited by Mat
Link to comment
Share on other sites

An example of actually searching. I'll have a go at replacement if you still can't do it yourself.

$sHaystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam urna urna, condimentum bibendum tincidunt ac, " & _
        "imperdiet non tellus. Aliquam dignissim enim cursus enim auctor congue in ullamcorper justo. Nunc luctus arcu " & _
        "quis urna dictum eu sagittis tellus elementum. Nunc viverra nunc quis purus vulputate pulvinar sed non lectus. " & _
        "Donec metus lacus, ultricies sed imperdiet ut, placerat quis libero. Cras eget placerat felis. Nullam vel erat " & _
        "nibh. Suspendisse enim neque, congue non vehicula nec, facilisis at eros. Morbi velit dui, viverra sit amet semper " & _
        "ac, gravida dignissim odio. Phasellus et rhoncus tortor. Proin tempor, ipsum eget sagittis malesuada, lacus turpis " & _
        "malesuada nisl, nec pellentesque orci augue nec libero. Sed risus nibh, posuere et iaculis sed, commodo et libero. " & _
        "Suspendisse potenti."

#include<WinAPI.au3>
#include<RichEditConstants.au3>
#include<EditConstants.au3>
#include<WindowsConstants.au3>

; A few constants you need that aren't included with AutoIt
Global Const $FR_FINDNEXT = 0x00000008
Global Const $FR_REPLACE = 0x00000010
Global Const $FR_REPLACEALL = 0x00000020
Global Const $FR_DIALOGTERM = 0x00000040
Global Const $FR_DIALOGMESSAGE = "commdlg_FindReplace"

; And a struct:
Global Const $tagFINDREPLACE = "dword lStructSize; hwnd hwndOwner; hwnd hInstance; dword Flags; ptr lpstrFindWhat; ptr lpstrReplaceWith; ushort wFindWhatLen; ushort wReplaceWithLen; " & _
        "ptr lCustData; ptr lpfnHook; ptr lpTemplateName;"

; First we initialise the struct we need for the find/replace dialog
Global $tFINDREPLACE = DllStructCreate($tagFINDREPLACE)
Global $tFindWhat = DllStructCreate("char Find[256]")
Global $tReplaceWith = DllStructCreate("char Replace[256]")
DllStructSetData($tFINDREPLACE, "hInstance", _WinAPI_GetModuleHandle(""))
DllStructSetData($tFINDREPLACE, "Flags", $FR_DOWN)
DllStructSetData($tFINDREPLACE, "lpstrFindWhat", DllStructGetPtr($tFindWhat))
DllStructSetData($tFINDREPLACE, "lpstrReplaceWith", DllStructGetPtr($tReplaceWith))
DllStructSetData($tFINDREPLACE, "wFindWhatLen", 255)
DllStructSetData($tFINDREPLACE, "wReplaceWithLen", 255)
DllStructSetData($tFINDREPLACE, "lCustData", 0)
DllStructSetData($tFINDREPLACE, "lpfnhook", 0)
DllStructSetData($tFINDREPLACE, "lpTemplateName", 0)
DllStructSetData($tFINDREPLACE, "lStructSize", DllStructGetSize($tFINDREPLACE))


; Create an example GUI
Global $hGUI, $hEdit, $GUI_Edit
Global $hSearchMenu, $hSearchMenu_Find, $hSearchMenu_Replace

$hGUI = GUICreate("Example for Find/replace dialog", 500, 400)
DllStructSetData($tFINDREPLACE, "hwndOwner", $hGUI)

$hSearchMenu = GUICtrlCreateMenu("&Search")
$hSearchMenu_Find = GUICtrlCreateMenuItem("&Find..." & @TAB & "Ctrl+F", $hSearchMenu)
$hSearchMenu_Replace = GUICtrlCreateMenuItem("&Replace..." & @TAB & "Ctrl+H", $hSearchMenu)

$hEdit = GUICtrlCreateEdit($sHaystack, 2, 2, 496, 396, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case $hSearchMenu_Find
            ; Find clicked. We default to selected text unless it includes newlines.
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "FindText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
        Case $hSearchMenu_Replace
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            ; I like to default the replace to the clipboard text.
            Local $sReplace = ClipGet()
            If StringInStr($sReplace, @CR) Or StringInStr($sReplace, @LF) Then
                $sReplace = ""
            Else
                $sReplace = StringReplace($sReplace, @TAB, " ")
            EndIf
            DllStructSetData($tReplaceWith, "Replace", $sReplace)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "ReplaceText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
    EndSwitch
WEnd

Func __FindReplace_Notify($hWnd, $iMsgId, $wParam, $lParam)
    #forceref $hWnd, $iMsgId, $wParam, $lParam
    Local $iFlags = DllStructGetData($tFINDREPLACE, "Flags"), _
            $fDir = BitAND($iFlags, $FR_DOWN) <> 0, _
            $fMatchCase = BitAND($iFlags, $FR_MATCHCASE) <> 0, _
            $sFind = DllStructGetData($tFindWhat, 1), $sReplace = DllStructGetData($tReplaceWith, 1), _
            $tSel = DllStructCreate("dword"), $tSelTo = DllStructCreate("dword")

    GUICtrlSendMsg($hEdit, $EM_GETSEL, DllStructGetPtr($tSel), DllStructGetPtr($tSelTo))

    Local $iSel = DllStructGetData($tSel, 1) - 1
    Local $iSelTo = DllStructGetData($tSelTo, 1) - 1

    Select
        Case BitAND($iFlags, $FR_FINDNEXT)
            Local $i

            If $fDir Then ; Search DOWN
                $i = StringInStr(StringTrimLeft(GUICtrlRead($hEdit), $iSelTo + 1), $sFind, $fMatchCase, 1) + $iSelTo
            Else ; Search UP
                $i = StringInStr(StringLeft(GUICtrlRead($hEdit), $iSel - 1), $sFind, $fMatchCase, -1) - 1
            EndIf
            If $i = -1 Then
                MsgBox(64, "Find/Replace", "Cannot find """ & $sFind & """.")
            Else
                If $fDir Then
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i, $i+StringLen($sFind))
                Else
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i+StringLen($sFind), $i)
                EndIf
                ControlFocus($hGUI, "", $hEdit)
            EndIf
        Case BitAND($iFlags, $FR_REPLACE)
            ConsoleWrite("REPLACE" & @CRLF)
        Case BitAND($iFlags, $FR_REPLACEALL)
            ConsoleWrite("REPLACEALL" & @CRLF)
        Case BitAND($iFlags, $FR_DIALOGTERM)
            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "")
    EndSelect
EndFunc   ;==>__FindReplace_Notify
Link to comment
Share on other sites

I've taken a brief look at the find function and that looks good, thanks for sharing that. Right now though, it is past midnight and I am worn out from writing functions in excel for my mum all day... but I will check back in here tomorrow if I can stay awake long enough.

Thanks.

Link to comment
Share on other sites

I've taken a brief look at the find function and that looks good, thanks for sharing that. Right now though, it is past midnight and I am worn out from writing functions in excel for my mum all day... but I will check back in here tomorrow if I can stay awake long enough.

Thanks.

In the mean time I did a bit of work on it, seemed like a useful enough snippet to have lying around. Replace is now working.

$sHaystack = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam urna urna, condimentum bibendum tincidunt ac, " & _
        "imperdiet non tellus. Aliquam dignissim enim cursus enim auctor congue in ullamcorper justo. Nunc luctus arcu " & _
        "quis urna dictum eu sagittis tellus elementum. Nunc viverra nunc quis purus vulputate pulvinar sed non lectus. " & _
        "Donec metus lacus, ultricies sed imperdiet ut, placerat quis libero. Cras eget placerat felis. Nullam vel erat " & _
        "nibh. Suspendisse enim neque, congue non vehicula nec, facilisis at eros. Morbi velit dui, viverra sit amet semper " & _
        "ac, gravida dignissim odio. Phasellus et rhoncus tortor. Proin tempor, ipsum eget sagittis malesuada, lacus turpis " & _
        "malesuada nisl, nec pellentesque orci augue nec libero. Sed risus nibh, posuere et iaculis sed, commodo et libero. " & _
        "Suspendisse potenti."

#include<WinAPI.au3>
#include<RichEditConstants.au3>
#include<EditConstants.au3>
#include<WindowsConstants.au3>

; A few constants you need that aren't included with AutoIt
Global Const $FR_FINDNEXT = 0x00000008
Global Const $FR_REPLACE = 0x00000010
Global Const $FR_REPLACEALL = 0x00000020
Global Const $FR_DIALOGTERM = 0x00000040
Global Const $FR_DIALOGMESSAGE = "commdlg_FindReplace"
Global Const $FR_HIDEMATCHCASE = 0x00008000
Global Const $FR_HIDEWHOLEWORD = 0x00010000

; And a struct:
Global Const $tagFINDREPLACE = "dword lStructSize; hwnd hwndOwner; hwnd hInstance; dword Flags; ptr lpstrFindWhat; ptr lpstrReplaceWith; ushort wFindWhatLen; ushort wReplaceWithLen; " & _
        "ptr lCustData; ptr lpfnHook; ptr lpTemplateName;"

; First we initialise the struct we need for the find/replace dialog
Global $tFINDREPLACE = DllStructCreate($tagFINDREPLACE)
Global $tFindWhat = DllStructCreate("char Find[256]")
Global $tReplaceWith = DllStructCreate("char Replace[256]")
DllStructSetData($tFINDREPLACE, "hInstance", _WinAPI_GetModuleHandle(""))
DllStructSetData($tFINDREPLACE, "Flags", BitOR($FR_DOWN, $FR_HIDEWHOLEWORD))
DllStructSetData($tFINDREPLACE, "lpstrFindWhat", DllStructGetPtr($tFindWhat))
DllStructSetData($tFINDREPLACE, "lpstrReplaceWith", DllStructGetPtr($tReplaceWith))
DllStructSetData($tFINDREPLACE, "wFindWhatLen", 255)
DllStructSetData($tFINDREPLACE, "wReplaceWithLen", 255)
DllStructSetData($tFINDREPLACE, "lCustData", 0)
DllStructSetData($tFINDREPLACE, "lpfnhook", 0)
DllStructSetData($tFINDREPLACE, "lpTemplateName", 0)
DllStructSetData($tFINDREPLACE, "lStructSize", DllStructGetSize($tFINDREPLACE))


; Create an example GUI
Global $hGUI, $hEdit, $GUI_Edit
Global $hSearchMenu, $hSearchMenu_Find, $hSearchMenu_Replace

$hGUI = GUICreate("Example for Find/replace dialog", 500, 400)
DllStructSetData($tFINDREPLACE, "hwndOwner", $hGUI)

$hSearchMenu = GUICtrlCreateMenu("&Search")
$hSearchMenu_Find = GUICtrlCreateMenuItem("&Find..." & @TAB & "Ctrl+F", $hSearchMenu)
$hSearchMenu_Replace = GUICtrlCreateMenuItem("&Replace..." & @TAB & "Ctrl+H", $hSearchMenu)

$hEdit = GUICtrlCreateEdit($sHaystack, 2, 2, 496, 396, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            ExitLoop
        Case $hSearchMenu_Find
            ; Find clicked. We default to selected text unless it includes newlines.
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "FindText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
        Case $hSearchMenu_Replace
            Local $sFind = StringStripWS(ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", ""), 3)
            If StringInStr($sFind, @CR) Or StringInStr($sFind, @LF) Then $sFind = ""
            DllStructSetData($tFindWhat, "Find", $sFind)

            ; I like to default the replace to the clipboard text.
            Local $sReplace = ClipGet()
            If StringInStr($sReplace, @CR) Or StringInStr($sReplace, @LF) Then
                $sReplace = ""
            Else
                $sReplace = StringReplace($sReplace, @TAB, " ")
            EndIf
            DllStructSetData($tReplaceWith, "Replace", $sReplace)

            Local $aRet = DllCall("comdlg32.dll", "hwnd", "ReplaceText", "ptr", DllStructGetPtr($tFINDREPLACE))
            If @error Then MsgBox(16, "Common dialog error!", "FindText Returned: " & $aRet[0] & @CRLF & @CRLF & _WinAPI_CommDlgExtendedError())

            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "__FindReplace_Notify")
    EndSwitch
WEnd

Func __FindReplace_Notify($hWnd, $iMsgId, $wParam, $lParam)
    #forceref $hWnd, $iMsgId, $wParam, $lParam
    Local $iFlags = DllStructGetData($tFINDREPLACE, "Flags"), _
            $fDir = BitAND($iFlags, $FR_DOWN) <> 0, _
            $fMatchCase = BitAND($iFlags, $FR_MATCHCASE) <> 0, _
            $sFind = DllStructGetData($tFindWhat, 1), $sReplace = DllStructGetData($tReplaceWith, 1), _
            $tSel = DllStructCreate("dword"), $tSelTo = DllStructCreate("dword")

    GUICtrlSendMsg($hEdit, $EM_GETSEL, DllStructGetPtr($tSel), DllStructGetPtr($tSelTo))

    Local $iSel = DllStructGetData($tSel, 1) - 1
    Local $iSelTo = DllStructGetData($tSelTo, 1) - 1

    Select
        Case BitAND($iFlags, $FR_FINDNEXT)
            Local $i

            If $fDir Then ; Search DOWN
                $i = StringInStr(StringTrimLeft(GUICtrlRead($hEdit), $iSelTo + 1), $sFind, $fMatchCase, 1) + $iSelTo
            Else ; Search UP
                $i = StringInStr(StringLeft(GUICtrlRead($hEdit), $iSel - 1), $sFind, $fMatchCase, -1) - 1
            EndIf
            If $i = -1 Then
                MsgBox(64, "Find/Replace", "Cannot find """ & $sFind & """.")
            Else
                If $fDir Then
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i, $i+StringLen($sFind))
                Else
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i+StringLen($sFind), $i)
                EndIf
                ControlFocus($hGUI, "", $hEdit)
            EndIf
        Case BitAND($iFlags, $FR_REPLACE)
            ; Find the next one
            Local $i

            If $fDir Then ; Search DOWN
                $i = StringInStr(StringTrimLeft(GUICtrlRead($hEdit), $iSelTo + 1), $sFind, $fMatchCase, 1) + $iSelTo
            Else ; Search UP
                $i = StringInStr(StringLeft(GUICtrlRead($hEdit), $iSel - 1), $sFind, $fMatchCase, -1) - 1
            EndIf

            If $i <> -1 Then
                $i -= StringLen($sFind)
                $i += StringLen($sReplace)
            EndIf

            If ControlCommand(GUICtrlGetHandle($hEdit), "", "", "GetSelected", "") = $sFind Then
                ; Make the replacement
                _SendMessageA(GUICtrlGetHandle($hEdit), $EM_REPLACESEL, True, DllStructGetPtr($tReplaceWith))
            EndIf

            If $i = -1 Then
                MsgBox(64, "Find/Replace", "Cannot find """ & $sFind & """.")
            Else
                If $fDir Then
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i, $i+StringLen($sFind))
                Else
                    GUICtrlSendMsg($hEdit, $EM_SETSEL, $i+StringLen($sFind), $i)
                EndIf
                ControlFocus($hGUI, "", $hEdit)
            EndIf
        Case BitAND($iFlags, $FR_REPLACEALL)
            GUICtrlSetData($hEdit, StringReplace(GUICtrlRead($hEdit), $sFind, $sReplace, 0, $fMatchCase), "")
        Case BitAND($iFlags, $FR_DIALOGTERM)
            GUIRegisterMsg(_WinAPI_RegisterWindowMessage($FR_DIALOGMESSAGE), "")
    EndSelect
EndFunc   ;==>__FindReplace_Notify

For the record, using this with richedits is considerably easier, as there is a built in function for searching which takes all the parameters and is far easier to use.

Link to comment
Share on other sites

You're using a rich edit? Why didn't you say ;) The original example I promised to dig up was for a richedit, so I rewrote it for a normal edit box :)

Look at _GUICtrlRichEdit_FindText. It even supports searching for whole words only, and some of the other funny flags which I don't know what they do ;)

Link to comment
Share on other sites

It even supports searching for whole words only, and some of the other funny flags which I don't know what they do ;)

Those flags are indeed funny. $FR_MATCHALEFHAMZA appears to be something to do with an Arabic symbol. I haven't looked into the other flags, but I doubt it would mean anything to me if I did. :)

Maybe these links will shed some light on it, although I could be completely wrong about that:

http://en.wikipedia.org/wiki/Aleph

http://en.wikipedia.org/wiki/Hamza

Edited by czardas
Link to comment
Share on other sites

WOW!!! Match...alefhamaza... uh... lo they are weird huh. Oh well, I didnt do any scripting today. A little bit of muckin round at school and right home to COD. I didnt feel like doing any scripting today, and I guess that considering I have had very few breaks in almost 3 months or so... well I'm sure u get the idea.

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...