Get a line of text using Scintilla
-
- New User
- Posts: 5
- Joined: Thu May 11, 2023 2:56 pm
- Location: Portsmouth, Uk
Get a line of text using Scintilla
Is there a way to get a line of text at the cursor position within an edit window and put that line into a string using Scintilla. I would be grateful for any help.
Re: Get a line of text using Scintilla
Could you please be more specific with your request?
Otherwise, the answer can only be yes.
Sorry, but maybe I just don't understand.
Otherwise, the answer can only be yes.
Sorry, but maybe I just don't understand.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: Get a line of text using Scintilla
Code: Select all
If OpenWindow(0, 0, 0, 330, 120, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScintillaGadget(0, 5, 5, 320, 80, 0)
*Text = UTF8("This is a simple ScintillaGadget with text..." + #LF$ + "More text" + #LF$ + "Even more text!")
ScintillaSendMessage(0, #SCI_SETTEXT, 0, *Text)
FreeMemory(*Text) ; der von UTF8() erstellte Puffer muss freigegeben werden, um ein Speicherleck zu vermeiden
ButtonGadget(1, 10, 90, 200, 20, "Copy line with cursor in it")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget() = 1
*buffer = AllocateMemory(1024)
If *buffer
ScintillaSendMessage(0, #SCI_GETCURLINE, MemorySize(*buffer) - 1, *buffer)
Debug PeekS(*buffer, -1, #PB_UTF8)
FreeMemory(*buffer)
EndIf
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
-
- New User
- Posts: 5
- Joined: Thu May 11, 2023 2:56 pm
- Location: Portsmouth, Uk
Re: Get a line of text using Scintilla
Thank you for the code on Get a line of text using Scintilla, it works fine.
Re: Get a line of text using Scintilla
https://azjio.narod.ru/PureBasic/pb_use ... ETTEXT.htm
Code: Select all
Procedure.s GetScintillaGadgetText()
Protected txtLen, *mem, text$
txtLen = ScintillaSendMessage(#SciGadget, #SCI_GETLENGTH) ; получает длину текста в байтах
*mem = AllocateMemory(txtLen + 2) ; Выделяем память на длину текста и 1 символ на Null
If *mem ; Если указатель получен, то
ScintillaSendMessage(#SciGadget, #SCI_GETTEXT, txtLen + 1, *mem) ; получает текст
; Считываем значение из области памяти
If g_Format = #PB_Ascii
text$ = PeekS(*mem, -1, #PB_Ascii)
Else
text$ = PeekS(*mem, -1, #PB_UTF8)
EndIf
FreeMemory(*mem)
ProcedureReturn text$
EndIf
ProcedureReturn ""
EndProcedure