Page 1 of 1

Right I've just about had it...

Posted: Mon Jun 16, 2008 4:02 pm
by Dale
OK I've spent half a day searching the forum for a solution to this:

I want to be able to grab some text that is highlighted in an EditorGadget. I found only one solution but it didn't work when I tried it. If I remember correctly from VB the solution involved GetSelLength, GetSelStart and GetSelEnd or something. Any help would be appreciated.

Many Thanks
Dale :?

Re: Right I've just about had it...

Posted: Mon Jun 16, 2008 4:11 pm
by rsts
Dale wrote:OK I've spent half a day searching the forum for a solution to this:

I want to be able to grab some text that is highlighted in an EditorGadget. I found only one solution but it didn't work when I tried it. If I remember correctly from VB the solution involved GetSelLength, GetSelStart and GetSelEnd or something. Any help would be appreciated.

Many Thanks
Dale :?
windows or all platform?

windows api = EM_GETSELTEXT (you can search for this in msdn)

Welcome to the forums :)

cheers

Posted: Mon Jun 16, 2008 4:14 pm
by srod

Code: Select all

If OpenWindow(0, 0, 0, 400, 300, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    EditorGadget(0, 8, 8, 306, 133) 
    ButtonGadget(1, 340, 8, 40, 20, "CLICK!")
    For a = 0 To 5 
      AddGadgetItem(0, a, "Line "+Str(a)) 
    Next 
    Repeat
      event = WaitWindowEvent()
      Select event
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              SendMessage_(GadgetID(0), #EM_EXGETSEL, 0, chr.CHARRANGE)
              If chr\cpmin < chr\cpmax
                a$ = Space(chr\cpmax-chr\cpmin)
                SendMessage_(GadgetID(0), #EM_GETSELTEXT, 0, @a$)
                Debug a$
              EndIf
          EndSelect
      EndSelect
    Until event = #PB_Event_CloseWindow 
  EndIf 

Posted: Mon Jun 16, 2008 4:14 pm
by Trond
rsts beat me to post, but he didn't give any code.

Code: Select all

Procedure.s GetSelectedText(Gadget)
  Protected GID = GadgetID(Gadget)
  Protected Start, Nd
  Protected Buffer.s
  SendMessage_(GID, #EM_GETSEL, @Start, @Nd)
  Buffer = Space(Nd-Start)
  SendMessage_(GID, #EM_GETSELTEXT, 0, @Buffer)
  ProcedureReturn Buffer
EndProcedure

#Editor = 0
#Button = 1

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))

EditorGadget(#Editor, 10, 10, 512-20, 384-30-22)
ButtonGadget(#Button, 10, 384-10-22, 150, 22, "Get selected text")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button
          Debug GetSelectedText(#Editor)
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver

Edit: And while I was writing that rsts beat me, srod beat me too! :evil:

But my code is prettier. :wink:

Posted: Mon Jun 16, 2008 4:15 pm
by srod
:lol:

Posted: Mon Jun 16, 2008 4:17 pm
by rsts
Trond wrote:rsts beat me to post, but he didn't give any code.

Edit: And while I was writing that rsts beat me, srod beat me too! :evil:

But my code is prettier. :wink:
I learned those one word/one sentence responses from you :)

Are you mellowing as you get older, or just in competition with srod, Sparkie and netmaestro?

:lol:

cheers

Posted: Mon Jun 16, 2008 4:26 pm
by Dale
I knew it had to be something really simple,

many thanks everyone :D

Re: Right I've just about had it...

Posted: Sat Oct 13, 2012 5:46 pm
by doctorized
I have a problem with your code.

Code: Select all

Procedure.s GetSelectedText(Gadget)
  Protected GID = GadgetID(Gadget)
  Protected Start, Nd
  Protected Buffer.s
  SendMessage_(GID, #EM_GETSEL, @Start, @Nd)
  Buffer = Space(Nd-Start)
  SendMessage_(GID, #EM_GETSELTEXT, 0, @Buffer)
  ProcedureReturn Buffer
EndProcedure

#Editor = 0
#Button = 1

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)

EditorGadget(#Editor, 10, 10, 512-20, 384-30-22)
ButtonGadget(#Button, 10, 384-10-22, 150, 22, "Get selected text")

For a = 0 To 5 
    AddGadgetItem(#Editor, a, "αβγδ" + Str(a)); ascii 225-229
Next 
   
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button
          Debug GetSelectedText(#Editor)
      EndSelect
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Text is not correct. Any suggestions?

Re: Right I've just about had it...

Posted: Sat Oct 13, 2012 5:54 pm
by netmaestro
Could you give more info about how the text is not correct?

Re: Right I've just about had it...

Posted: Sat Oct 13, 2012 6:28 pm
by skywalk
I use this template to document what settings are required prior to compile. :wink:

Code: Select all

; COMPILER OPTIONS:
;   [ ] Enable inline ASM support
;   [x] Create unicode executable
;   [ ] Create threadsafe executable
;   [ ] Enable OnError lines support
;   [ ] Enable XP skin support
;   [ ] Request Administrator mode for Windows Vista
;   [ ] Request User mode for Windows Vista (no virtualization)
;   Library Subsystem:  
;   Executable Format:  Windows  ;|Console|Shared DLL
;   CPU:                All      ;|Dynamic|w/MMX|w/3DNOW|w/SSE|w/SSE2

Re: Right I've just about had it...

Posted: Sat Oct 13, 2012 7:02 pm
by RASHAD
Try

- File --> File Format --> Encoding :Utf8
- Compiler --> Compiler Options --> Create unicode exe

Re: Right I've just about had it...

Posted: Sun Oct 14, 2012 11:22 am
by doctorized
netmaestro wrote:Could you give more info about how the text is not correct?
If I select "αβγδ2" the text I get is "aß d2".
RACHAD's instructions solved my problem! thanx a lot!! :D