get selected text of editor gadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

get selected text of editor gadget

Post by Yian_The_Craft »

title says it all :P
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Edit:

Sorry, didn't realise this was a feature request, hence the code below.
(I used "view posts since last visit" and didn't check the forum name.)
Anyhow, just in case it was a request for code, will leave the code below.

Code: Select all

winID=OpenWindow(0,0,0,300,300,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar,"SOMETHING")
If winID
  gadList=CreateGadgetList(WindowID(0))
  If gadList
    edGadID=EditorGadget(1,5,5,290,290)
    If edGadID
      
      lastSz=0  ; klurge - to stop debug window scrolling until change
      lastCh=0  ; klurge - to stop debug window scrolling until change
      
      Repeat
        Event = WaitWindowEvent()
        
        ; ------- DEFINE YOUR OWN TRIGGER
        ; This triggers when any selection done.

        SendMessage_(edGadID,#EM_EXGETSEL,0,Range.CHARRANGE)
        siz=Range\cpMax-Range\cpMin
        If siz<>0 And (lastSz<>siz Or lastCh<>Range\cpMin)
          lastSz=siz
          lastCh=Range\cpMin
          w.s=Space(siz*2)
          SendMessage_(edGadID,#EM_GETSELTEXT,0,w)
          Debug Str(siz)+": "+w
        EndIf
        
      Until Event = #PB_EventCloseWindow
    EndIf
  EndIf
EndIf
@}--`--,-- A rose by any other name ..
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

Post by Yian_The_Craft »

many thanks! :D But how did you think of that? I'm a bit confused since you don't seem to use stuff in the manual...like sendmessage_ and #EM_GETSELTEXT
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Hi Yian_The_Craft.

First, wish I could say I worked it out but I didn't. I learned it and other things from the smarter folk using this forum.

Second, it is a winapi call, not a PureBasic command. PureBasic, or the registered version, allows for calls to windows functions. All you need to to is stick a "_" after the windows function name, eg, SendMessage(.. becomes SendMessage_(..

You can find these functions in the windows SDK (downloadable from MS) or the older help file (sure to be a link to that somewhere in the forums).

If you read through the forums you will find bucketloads of useful stuff from the gurus here. You can also download a massive amount of code from http://www.purearea.net (the code archive).

The forum for asking questions is the beginners forum, help comes faster on that forum (this one is requests to Fred to add functionality to PureBasic) After I first answered your post and then saw where it was posted I nearly deleted my response because I thought you might be requesting that this be added to functionality, eg something like:
  • w.s=GetEditorSelectedText(#Gadget)
Anyhow, welcome to the boards and success to you. :)
Last edited by Dare2 on Sun Sep 12, 2004 12:11 pm, edited 1 time in total.
@}--`--,-- A rose by any other name ..
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

Post by Yian_The_Craft »

Thanks,it would be good if it was added to functionality.
Post Reply