Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selection on a scintilla window
#1
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!
#2
Code:
Copy      Help
SendMessage(hwn SCI.SCI_SETSEL i i+8)
http://www.scintilla.org/ScintillaDoc.html#SCI_SETSEL
#3
Many thanks indeed. Could you please give me an example of using the find text method (SCI.SCI_FINDTEXT ?).
#4
Is the scintilla control in the same process as the macro?
#5
I am afraid not. I am searchnig for text on a Notepad++ window
#6
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.
#7
Macro Macro1684
Code:
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)
#8
Many thanks indeed.
#9
Function ScintillaGetText
Code:
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
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
Code:
Copy      Help
int c=GetQmCodeEditor
;int w=win("Notepad++" "Notepad++")
;int c=child("" "Scintilla" w)

str s
ScintillaGetText c s
out s
#10
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?)
#11
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.
#12
ok, thank you!
#13
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:
Code:
Copy      Help
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:
Code:
Copy      Help
SCI_REPLACESEL(<unused>, const char *text)
#14
Macro Macro2431
Code:
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)
pm.WriteStr(newText)
SendMessage c SCI.SCI_SETTEXT 0 pm.address
#15
Yes thank you!!!
It works!!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)