Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
I need to make a selection on the text of a scintilla window. Could you please advise on the equivalent of
SendMessage(hwn EM_SETSEL i i+8)
on a sciltilla window.
Many thanks, Best regards!
Posts: 12,140
Threads: 142
Joined: Dec 2002
Posts: 1,058
Threads: 367
Joined: Oct 2007
Many thanks indeed. Could you please give me an example of using the find text method (SCI.SCI_FINDTEXT ?).
Posts: 12,140
Threads: 142
Joined: Dec 2002
Is the scintilla control in the same process as the macro?
Posts: 1,058
Threads: 367
Joined: Oct 2007
I am afraid not. I am searchnig for text on a Notepad++ window
Posts: 12,140
Threads: 142
Joined: Dec 2002
Will need to use __ProcessMemory class.
Maybe better would be to get all text and then find/findrx/etc? I never used SCI_FINDTEXT, don't know how it is different.
Posts: 12,140
Threads: 142
Joined: Dec 2002
Macro
Macro1684
int w=win("Notepad++" "Notepad++")
int c=child("" "Scintilla" w)
str textToFind="Verdana"
;____________________________
SCI.Sci_TextToFind ttf
__ProcessMemory m
int nb=sizeof(ttf)+textToFind.len+1
lpstr p=m.Alloc(c nb)
ttf.chrg.cpMin=0; ttf.chrg.cpMax=1000000000; ttf.lpstrText=p+sizeof(ttf)
str pack.fromn(&ttf sizeof(ttf) textToFind textToFind.len)
m.Write(pack nb)
out SendMessage(c SCI.SCI_FINDTEXT 0 p)
Posts: 1,058
Threads: 367
Joined: Oct 2007
Posts: 12,140
Threads: 142
Joined: Dec 2002
Function
ScintillaGetText
;/
function hwndSci str&s
;Gets text of a Scintilla control or a Scintilla-based control.
;Supports controls in other processes too.
;QM uses Scintilla for its code editor, output, statusbar and some other controls.
opt noerrorshere 1
int pid
if(!GetWindowThreadProcessId(hwndSci &pid)) end ERR_HWND
int n=SendMessage(hwndSci SCI.SCI_GETTEXTLENGTH 0 0)
if(!n) s=""; ret
n+1
if pid=GetCurrentProcessId
,s.fix(SendMessage(hwndSci SCI.SCI_GETTEXT n s.all(n)))
else
,__ProcessMemory m
,n=SendMessage(hwndSci SCI.SCI_GETTEXT n m.Alloc(hwndSci n))
,m.ReadStr(s n)
Macro
Macro2333
int c=GetQmCodeEditor
;int w=win("Notepad++" "Notepad++")
;int c=child("" "Scintilla" w)
str s
ScintillaGetText c s
out s
Posts: 771
Threads: 264
Joined: Jul 2012
This is really nice, it works even when the notepad++ window is hidden!!
Is there a way to SET the text?
(text that is selected and all the text?)
Posts: 12,140
Threads: 142
Joined: Dec 2002
Yes. Try to find the message in Scintilla documentation. I'll help with __ProcessMemory if need.
But I'm afraid it is not good to modify text in other programs with Scintilla API. The program may be unaware about it. Eg Undo may not work etc.
Nothing wrong to just select text with Scintilla API. Will not need __ProcessMemory. Just single SendMessage. Then can paste or key.
Posts: 771
Threads: 264
Joined: Jul 2012
Posts: 771
Threads: 264
Joined: Jul 2012
I tried to compose the code for setting the text for the complete text and selected text but it was to difficult.
I found here:
http://www.scintilla.org/ScintillaDoc.html#SCI_SETTEXT
The following two text modification commands:
1)
This replaces all the text in the document with the zero terminated text string you pass in:
SCI_SETTEXT(<unused>, const char *text)
2)
The currently selected text between the anchor and the current position is replaced by the 0 terminated text string. If the anchor and current position are the same, the text is inserted at the caret position. The caret is positioned after the inserted text and the caret is scrolled into view:
SCI_REPLACESEL(<unused>, const char *text)
Posts: 12,140
Threads: 142
Joined: Dec 2002
Macro
Macro2431
int w=win("" "Notepad++")
int c=child("" "Scintilla" w)
str newText="abc αβγ" ;;if αβγ is garbage, Notepad++ is not using UTF-8 text encoding or QM is not in Unicode mode
__ProcessMemory pm.Alloc(c newText.len+1)
pm.WriteStr(newText)
SendMessage c SCI.SCI_SETTEXT 0 pm.address
Posts: 771
Threads: 264
Joined: Jul 2012
Yes thank you!!!
It works!!!!