Hello, sorry for my English, I'm from Spain.
This is the Find Text Function.
No Loop for single replacement.
Code:
; ******************************PLACE IN feature_demo.ahk********************
^R::
SearchText:="Hello"
ReplaceText:="Morning"
Lenght_String:= % StrLen(SearchText)
cRichEdit(REdit1, "FindText",SearchText,Lenght_String,ReplaceText)
Return
; ***************************************************************************
; *******************************PLACE IN cRichEdit.ahk***********************
Else If _action = FindText
{
VarSetCapacity(FindText,12,0)
Loop
{
;--------------------------------REDIT TEXT LENGHT---------------------
VarSetCapacity(_tmp1, 8, 0)
NumPut(0, _tmp1, 0)
NumPut(_tmp2, _tmp1, 4)
Text_Lengt:= % DllCall("user32.dll\SendMessage", "UInt", _ctrlID, "UInt", 0x45F, "UInt", &_tmp1, "UInt", "0")
;--------------------------------------------------------------------------------
NumPut(Result,FindText)
NumPut(Text_Lengt,FindText,4)
NumPut(&opt1,FindText,8)
Result:=DllCall("SendMessage","UInt",_ctrlID,"UInt",0x438,"UInt",0x5,"UInt",&FindText)
If (Result=-1)
Break
;---------------------------------SELECT RANGE TEXT----------------
string_start:=Result
string_end:=Result+opt2
VarSetCapacity(_tmp1, 8, 0)
NumPut(string_start, _tmp1, 0, "Int")
NumPut(string_end, _tmp1, 4, "Int")
DllCall("user32.dll\SendMessage", "UInt", _ctrlID, "UInt", 0x437, "UInt", "0", "UInt", &_tmp1)
;------------------SEND NEW TEXT or COLOUR REPLACE or ... -------------------------
_tmp2 := true
DllCall("user32.dll\SendMessage", "UInt", _ctrlID, "UInt", 0xC2, "UInt", _tmp2, "UInt", &opt3)
;------------------------------------------------------------------------------
Result:=1
}
Return
}
;*****************************************************************************************
Use this for colour replacement.
Code:
color:="Red"
_cnt1 := Instr(_predef, color . "|")
If (_cnt1)
color := SubStr(_predef, (_cnt1 - 7), 6)
If (SubStr(opt3, 1, 2) = "0x")
StringTrimLeft, color, color, 2
color := "0x" . SubStr(color, 5, 2) . SubStr(color, 3, 2) . SubStr(color, 1, 2)
VarSetCapacity(_tmp1, 60, Chr(0)) ; CHARFORMAT struct
NumPut(60, _tmp1, 0, "Int") ; cbSize
NumPut(0x40000000, _tmp1, 4) ; dwMask
NumPut(color, _tmp1, 20) ; crTextColor
; ** apply the colour
DllCall("user32.dll\SendMessage", "UInt", _ctrlID, "UInt", 0x444, "UInt", "1", "UInt", &_tmp1)
;------------------------------------------------------------------------------
Result:=Result+opt2