Indicate change in text

Just starting out? Need help? Post your questions and find answers here.
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Indicate change in text

Post by BjornF »

Dear All,

I have a programme that shows records in a couple of editor fields. The user can change the text in the fields.
What I would like to do is to signal to the user that he has changed the text by changing the background colour.

Just now I can think of two ways of doing it.
1. record content then use a timer that compares the recorded with the present content every 0.5s
2. record content then use EventGadget for the editorfields to indicate that something has happened, compare texts as above

However both seem to have their disadvantages:
1. seems like a waste of resources and will continue running even when the programme is in the background (this could be solved if there is a Window - lostfocus, but I can't find one)
2. this is evoked for any number of reasons, not all are related to changes in the text

Is there a smart(er) way of doing it?

all the best / Björn
juror
Enthusiast
Enthusiast
Posts: 232
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Indicate change in text

Post by juror »

Windows only:
EM_GETMODIFY
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Re: Indicate change in text

Post by BjornF »

Nice, but do you know anything about the reliability? At least someone seems to have had problems with it...

http://msdn.microsoft.com/en-us/library ... s.85).aspx
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: Indicate change in text

Post by Num3 »

Code: Select all

 Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #String_minutes
        If EventType = #PB_EventType_Change ; <---- DING DING
          Do extra check to see if it is equal to last value
          etc....
        EndIf
      EndIf
Little John
Addict
Addict
Posts: 4793
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Indicate change in text

Post by Little John »

BjornF wrote:[EventGadget] is evoked for any number of reasons, not all are related to changes in the text

Is there a smart(er) way of doing it?
I use #PB_Event_Gadget together with #PB_EventType_Change:

Code: Select all

      event = WaitWindowEvent()

      If event = #PB_Event_Gadget
         Select EventGadget()
            Case #MyEditField
               Select EventType()
                  Case #PB_EventType_Change
                     ; do something
               EndSelect
            [...]
Works fine for me.

Regards, Little John

//edit: Num3 was some seconds faster. :-)
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Re: Indicate change in text

Post by BjornF »

Excellent ! :D

Thank you for the help, just the thing I was after. / Björn


edit: I just tried it, and couldn't get it to work :( :( :(
Did you try it? (Editorgadget isn't noted as one of the gadgets it can be used on)
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Re: Indicate change in text

Post by Num3 »

BjornF wrote:Excellent ! :D

Thank you for the help, just the thing I was after. / Björn


edit: I just tried it, and couldn't get it to work :( :( :(
Did you try it? (Editorgadget isn't noted as one of the gadgets it can be used on)
Upsss you forgot to mention it was for an editor gadget!

I don't think it will work with that :(
Little John
Addict
Addict
Posts: 4793
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Indicate change in text

Post by Little John »

Ooops ...

For an EditorGadget, use this code (slightly modified for recent PB versions after a code by srod):

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   EditorGadget(0, 8, 8, 306, 133)
   ;Add the following line to enable the editor gadget to send #EN_CHANGE notifications.
   SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0,0)|#ENM_CHANGE)
   
   For a = 0 To 5
      AddGadgetItem(0, a, "Line " + Str(a))
   Next
   
   Repeat
      Event = WaitWindowEvent()
      Select EventType()
         Case #PB_EventType_Change
            Debug "changed"
      EndSelect
   Until Event = #PB_Event_CloseWindow
EndIf
Regards, Little John
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Re: Indicate change in text

Post by BjornF »

Thank you, I'll have a go with that one. / all the best, Björn
Post Reply