Right I've just about had it...

Just starting out? Need help? Post your questions and find answers here.
Dale
New User
New User
Posts: 4
Joined: Wed May 28, 2008 8:20 am

Right I've just about had it...

Post 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 :?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

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

Post 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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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 
I may look like a mule, but I'm not a complete ass.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post 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
Dale
New User
New User
Posts: 4
Joined: Wed May 28, 2008 8:20 am

Post by Dale »

I knew it had to be something really simple,

many thanks everyone :D
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

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

Post 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?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post by netmaestro »

Could you give more info about how the text is not correct?
BERESHEIT
User avatar
skywalk
Addict
Addict
Posts: 4212
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

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

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

Try

- File --> File Format --> Encoding :Utf8
- Compiler --> Compiler Options --> Create unicode exe
Egypt my love
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

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

Post 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
Post Reply