Threasafe Flashing Text

Share your advanced PureBasic knowledge/code with the community.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Threasafe Flashing Text

Post by kinglestat »

I've modified ar-s example with a method I use as a visual flash which people might find useful. It should also be threadsafe.

Code: Select all


Enumeration
  #WIN
  #Affiche
  #gadgetone
EndEnumeration

Structure stFlashError   
   count.i
   gadget.i
EndStructure

Global                   muFlash.i = CreateMutex()
Global NewList          gFlash.stFlashError()

Procedure         FlashError( a.l, b.l, dwUser.l, d.l, E.i )
  
   Protected      uDelay.i
  
   If TryLockMutex( muFlash )
     ChangeCurrentElement( gFlash(), dwUser )
     gFlash()\count - 1
     uDelay = gFlash()\count * 15
     
     If uDelay < 125 : uDelay = 125 : EndIf
     
     If gFlash()\count % 2
        SetGadgetColor( gFlash()\gadget, #PB_Gadget_BackColor, $E81717 )    
     Else
        SetGadgetColor( gFlash()\gadget, #PB_Gadget_BackColor, -1 )
     EndIf 
        
     If gFlash()\count > 0 
        timeSetEvent_( uDelay, 50, @FlashError(), dwUser, #TIME_ONESHOT )  
     EndIf
  
     UnlockMutex( muFlash )
   EndIf 
  
EndProcedure

If OpenWindow(#WIN, 450, 200, 377, 24, "clignote", #PB_Window_SystemMenu|#PB_Window_TitleBar)
    StringGadget(#Affiche, 0, 0, 375, 22, "My Text", #PB_String_ReadOnly)
    
EndIf

LockMutex( muFlash )
   AddElement( gFlash() ) 
      gFlash()\count    = 16
      gFlash()\gadget   = #Affiche      
      d = @gFlash()
   UnlockMutex( muFlash )
   
   timeSetEvent_( 25, 10, @FlashError(), d, #TIME_ONESHOT )

Repeat
  Select WaitWindowEvent()
    
    Case #PB_Event_CloseWindow
      Select EventWindow()
        Case #WIN
          CloseWindow(#WIN)
          Break
      EndSelect
  EndSelect
ForEver

I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: Threasafe Flashing Text

Post by akj »

@kinglestat:
You are missing a call to timeKillEvent_() which the documentation says is required
http://msdn.microsoft.com/en-us/library/aa448195.aspx
Anthony Jordan
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Re: Threasafe Flashing Text

Post by kinglestat »

the docs specify "periodic". I am using the TIME_ONESHOT which, as name implies, means calling it once.
cheers
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: Threasafe Flashing Text

Post by akj »

@kinglestat:

Yes, my mistake. Sorry.
Anthony Jordan
Post Reply