Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selection on a scintilla window
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!
Copy      Help
SendMessage(hwn SCI.SCI_SETSEL i i+8)
Many thanks indeed. Could you please give me an example of using the find text method (SCI.SCI_FINDTEXT ?).
Is the scintilla control in the same process as the macro?
I am afraid not. I am searchnig for text on a Notepad++ window
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.
Macro Macro1684
Copy      Help
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)
Many thanks indeed.
Function ScintillaGetText
Copy      Help
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

if pid=GetCurrentProcessId
,s.fix(SendMessage(hwndSci SCI.SCI_GETTEXT n s.all(n)))
,__ProcessMemory m
,n=SendMessage(hwndSci SCI.SCI_GETTEXT n m.Alloc(hwndSci n))
,m.ReadStr(s n)
Macro Macro2333
Copy      Help
int c=GetQmCodeEditor
;int w=win("Notepad++" "Notepad++")
;int c=child("" "Scintilla" w)

str s
ScintillaGetText c s
out s
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?)
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.
ok, thank you!
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:

The following two text modification commands:

This replaces all the text in the document with the zero terminated text string you pass in:
Copy      Help
SCI_SETTEXT(<unused>, const char *text)

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:
Copy      Help
SCI_REPLACESEL(<unused>, const char *text)
Macro Macro2431
Copy      Help
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)
SendMessage c SCI.SCI_SETTEXT 0 pm.address
Yes thank you!!!
It works!!!!

Forum Jump:

Users browsing this thread: 1 Guest(s)