It works now.
#SCI_FINDTEXT accepts
a structure pointer as second argument so you have to
allocate memory for this pointer.
I noticed that
Search\chrgText\CpMin and
Search\chrgText\CpMax are not returned correctly perhaps because PB uses a 2 years old version of scintilla
Code: Select all
EnableExplicit
Global SCI
Procedure GetProcessFromWindow(hwnd)
Protected PID, result
If GetWindowThreadProcessId_(hwnd, @PID)
result=OpenProcess_(#PROCESS_ALL_ACCESS, #False, PID)
EndIf
ProcedureReturn result
EndProcedure
Procedure ScFindText(Text$, Beginpos=0, Endpos=1000, Flag=0)
Protected proc
Protected *Search.SCTextToFind,Search.SCTextToFind, pos=-1
Protected *Text, len
proc=GetProcessFromWindow(SCI)
If proc
len=Len(Text$)+1
*Text=VirtualAllocEx_(proc, 0, len, #MEM_RESERVE | #MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
*Search=VirtualAllocEx_(proc, 0, SizeOf(SCTextToFind), #MEM_RESERVE | #MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
If *Text
WriteProcessMemory_(proc, *Text, @Text$, len, #Null)
Search\chrg\cpMin=Beginpos
Search\chrg\cpMax=Endpos
Search\lpstrText=*Text
Search\chrgText\cpMin=Beginpos
Search\chrgText\cpMax=Endpos
If *Search
WriteProcessMemory_(proc, *Search, @Search, SizeOf(SCTextToFind), #Null)
pos=SendMessage_(SCI, #SCI_FINDTEXT, Flag, *Search)
If pos>-1
MessageRequester("",str(Search\chrg\CpMin)+" "+str(Search\chrgText\CpMin)+" "+str(Search\chrg\cpMax)+" "+str(Search\chrgText\cpMax))
EndIf
VirtualFreeEx_(proc, *Search, SizeOf(SCTextToFind), #MEM_RELEASE)
EndIf
VirtualFreeEx_(proc, *Text, len, #MEM_RELEASE)
EndIf
CloseHandle_(proc)
EndIf
ProcedureReturn pos
EndProcedure
; Main
SCI=Val(GetEnvironmentVariable("PB_Tool_Scintilla"))
If SCI
Define pos=ScFindText("e")
MessageRequester("Word Found", "pos="+str(pos))
EndIf
End