about the editor gadget

Just starting out? Need help? Post your questions and find answers here.
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

about the editor gadget

Post by Yian_The_Craft »

Hello,about that editorgadget...is there any way to delete selected text,but not with back space,instead when a menuevent() happens..?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

For windows, here is one way:

Code: Select all

#_btnGad=1
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 
    btnID=ButtonGadget(#_btnGad,10,1,50,20,"DELETE")
    edGadID=EditorGadget(2,5,25,290,290) 
    If edGadID 
      Repeat 
        Event = WaitWindowEvent()
        If Event=#PB_Event_Gadget 
          If EventGadgetID()=#_btnGad And EventType()=#PB_EventType_LeftClick
            z.s=""
            SendMessage_(edGadID,#EM_REPLACESEL,1,z)
          EndIf
        EndIf 
      Until Event = #PB_EventCloseWindow 
    EndIf 
  EndIf 
EndIf
Tons of good stuff in the MS platform SDK help. Index search on EM_ for some useful SendMessage_( edit flags
@}--`--,-- 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 many thanks. 8)
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

Post by Yian_The_Craft »

Sorry but I have nother question ;)
How can I change the color of the selected text in the editorgadget?
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Edited:

Code: Select all

#_btnGad=1 
#_btnGad2=2 
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 
    btnID=ButtonGadget(#_btnGad,10,1,50,20,"DELETE") 
    btnID2=ButtonGadget(#_btnGad2,80,1,100,20,"CHANGE COLOR") 
    edGadID=EditorGadget(3,5,25,290,290) 
    If edGadID 
      Repeat 
        Event = WaitWindowEvent() 
        If Event=#PB_Event_Gadget 
          If EventGadgetID()=#_btnGad And EventType()=#PB_EventType_LeftClick 
            z.s="" 
            SendMessage_(edGadID,#EM_REPLACESEL,1,z) 
          ElseIf EventGadgetID()=#_btnGad2 And EventType()=#PB_EventType_LeftClick 
            Format.CHARFORMAT
            Format\cbSize=SizeOf(CHARFORMAT)
            Format\dwMask=#CFM_COLOR
            Format\crTextColor=RGB(Random(255),Random(255),Random(255))
            SendMessage_(edGadID,#EM_SETCHARFORMAT,#SCF_SELECTION,Format)
          EndIf 
        EndIf 
      Until Event = #PB_EventCloseWindow 
    EndIf 
  EndIf 
EndIf
Yian, you should really read the MS documentation...

RichEdit Controls:
http://msdn.microsoft.com/library/en-us ... ntrols.asp

Edit Controls (This applies too):
http://msdn.microsoft.com/library/en-us ... ntrols.asp
Last edited by PolyVector on Fri Sep 17, 2004 2:23 am, edited 1 time in total.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@PolyVector ... Missing Event catch for #_btnGad2. Change Gadget# in line 17 from #_btnGad to #_btnGad2.

Code: Select all

ElseIf EventGadgetID()=#_btnGad And EventType()=#PB_EventType_LeftClick
to

Code: Select all

ElseIf EventGadgetID()=#_btnGad2 And EventType()=#PB_EventType_LeftClick 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

ROFL... Yeah, I just threw that together before bed....silly me! Thanks for catching that. It's not my coding style so I didn't notice it :D
Yian_The_Craft
User
User
Posts: 15
Joined: Sun Sep 12, 2004 6:41 am

Post by Yian_The_Craft »

Thanks poly,I had looked through the MS pages but I ddin't find the color commands.Also,I had searched this forum and got some really complicated stuff and people saying you MUST use windows callback to do it.Thanks again! :D
Hmm ok this is some stuffI don't get:
Format.CHARFORMAT
Format\cbSize=SizeOf(CHARFORMAT)
Format\dwMask=#CFM_COLOR
Format\crTextColor=RGB(Random(255),Random(255),Random(255))
Is this how you assign types in PB?
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

This creates a variable called 'Format' of type CHARFORMAT

Code: Select all

Format.CHARFORMAT
This sets the 'cbSize' element of Format the size(in bytes) of a CHARFORMAT structure... Windows needs this to prevent buffer overflows...

Code: Select all

Format\cbSize=SizeOf(CHARFORMAT) 
This assigns the 'crTextColor' element of Format to a random RGB value...

Code: Select all

Format\crTextColor=RGB(Random(255),Random(255),Random(255)) 
It's pretty simple stuff... The thread that I believe you are refering to was about the Edit class... You do need to use callbacks to modify that... We're talking about the RichEdit class here...
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Heya Yian_The_Craft,

I'm not sure how far along you are so if I am telling you something you already know, please forgive. :)

(Also, have a windows bias in the following.)

You have a core PureBasic (what you see in the help).

You have an extended PureBasic, which adds functionality by exposing the operating system or user libraries.

Recognised windows functions have an underscore appended to the function name.

So:

In PB you can define structures and use them to build your own variable types.

You define a variable type using "dot" notation, eg myVar.l for long. Or myVar.myStructure for structures.

Elements or fields within the structured variable are accessed by using a backslash, eg, myVar\myField.

PB also has a number of windows structures it recognises.

CHARFORMAT is one such. The "external" or "OpSys" structures are assigned to a variable name in the same way as a normal PB structure, you just don't need to define them.

In the code you showed, "Format" is defined as variable type (structured as) CHARFORMAT.

Just to confuse, most code shown here mixes three things:

1: Core PB functionality.

2: Recognised windows calls and structures, etc, which are not PB per se but which can be used in PB.

3: And user libraries. This one threw me for ages, because there was nothing in the help nor the windows SDK help to cover these, and most code show forgets to advise there is a library dependency.

Anyhow, by now you're bored to tears, enlightened, or confused. :P

Edit: What PolyVector said (sneaking in a post whilst I was still typing) but in verbose mode. :)
@}--`--,-- 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 »

OK I'm not new to programming,just PB.I am self-taught(since 99) so there are some holes in my knowledge.Types are something I have be learning recently and I haven't used it much.
Thanks to all!
But I have one question...we define the var Format as type CHARRANGE or whatever it was,but why didn't we have to specify that the type CHARRANGE includes cpMin for example?Or is that automatically recognised because it is a windows type? Thanks :)
Also...could you please post an example for how to use #EM_FINDTEXT ? I get confused with it because it requires some weird stuff... :?
Post Reply