Just a laugh

Everything else that doesn't fall into one of the other PB categories.
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Just a laugh

Post by Character »

To have just a quick laugh I wrote this for my son who was in a bad mood.

:lol:

Feeling blue? Run this little fellow a few times.

[url=http://]> Download[/url] [download removed]
Last edited by Character on Wed Jan 16, 2008 10:14 am, edited 2 times in total.
Cessante causa cessat effectus
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

:lol:
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Took me a while to figure out, then I turned on my speakers!!!
SCRJ
User
User
Posts: 93
Joined: Sun Jan 15, 2006 1:36 pm

Post by SCRJ »

lol :lol:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Did his mood improve? :D
I may look like a mule, but I'm not a complete ass.
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Mood

Post by Character »

Yes!
His mood definitely improved. What a simple program can do :D

PS
I made a yellow version with the PureCOLOR library and improved the random functionality.



[picture removed]
Last edited by Character on Fri Jan 18, 2008 10:00 pm, edited 3 times in total.
Cessante causa cessat effectus
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Update

Post by Character »

A small update:
Program now remains in the systray when closed.
Some surprising sounds for those who forget about it..

[url=http://]> Update zip[/url] [download removed]

PS
Had some strange effects before compiling. Got a strange linker error.
When I unchecked the safethread option in the compiler it disappeared.
Anybody seen same problem?

Anyway.. I also attached the code when you might have a tip or trick for me.
(don't shoot me, I'm not a pro.. totaly freeware stuf, just for kids)


[edit]

Code: Select all

; Coded by Character - 2006  using:
; PureBasic v4.00 (Windows - x86)
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
; PureCOLOR, RegINI_Lib, Win32 API
; PureBasic forums



;- Mutex Creation
MutexID.l=CreateMutex_(0,1,"Hahaha!")
MutexError.l=GetLastError_()
If MutexID=0 Or MutexError<>0
  ReleaseMutex_(MutexID)
  CloseHandle_(MutexID)
  End
EndIf

;- Window Constants
Enumeration
  #Window_0
  #SysTrayIcon
EndEnumeration

;- Gadget Constants
Enumeration
  #Button_0
  #Radio_0
  #Radio_1
  #TrackBar_0
  #Sound_0
  #Sound_1
  #Sound_2
  #Sound_3
  #Sound_4
  #Sound_5
  #Sound_6
  #Sound_7
EndEnumeration

;- Image Inclusion
Image0=CatchImage(0,?Image0)

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Comic Sans MS", 48, #PB_Font_Bold)
Global FontID2
FontID2 = LoadFont(2, "Comic Sans MS", 10)
Global FontID3
FontID3 = LoadFont(3, "Comic Sans MS", 10, #PB_Font_Bold)

;- Catch Sound
If InitSound()=0 
  MessageRequester("Fout audio systeem","Audio omgeving kan niet geïnitaliseerd worden.", #MB_ICONERROR)
  End
EndIf  
CatchSound(#Sound_0,?Sound0)
CatchSound(#Sound_1,?Sound1)
CatchSound(#Sound_2,?Sound2)
CatchSound(#Sound_3,?Sound3)
CatchSound(#Sound_4,?Sound4)
CatchSound(#Sound_5,?Sound5)
CatchSound(#Sound_6,?Sound6)
CatchSound(#Sound_7,?Sound7)

;- Sound Inclusion
DataSection
Sound0: 
  IncludeBinary "Sound\Hahaha0.wav"
Sound1: 
  IncludeBinary "Sound\Hahaha1.wav"
Sound2: 
  IncludeBinary "Sound\Hahaha2.wav"
Sound3: 
  IncludeBinary "Sound\Hahaha3.wav"    
Sound4: 
  IncludeBinary "Sound\Info.wav"
Sound5: 
  IncludeBinary "Sound\Navi.wav"
Sound6: 
  IncludeBinary "Sound\Hmm.wav"
Sound7: 
  IncludeBinary "Sound\Gigglef.wav"  
EndDataSection


If OpenWindow(#Window_0,477,385,300,300,"Hahaha!",#PB_Window_SystemMenu|#PB_Window_TitleBar)
  If CreateGadgetList(WindowID(#Window_0))
    ButtonGadget(#Button_0,10,50,280,200,"CLICK!",#PB_Button_Default)
    SetGadgetFont(#Button_0,FontID1)
    TrackBarGadget(#TrackBar_0, 20, 10, 260, 30, 0, 2, #PB_TrackBar_Ticks)
    OptionGadget(#Radio_0,30,260,80,30," Normal")
    SetGadgetFont(#Radio_0,FontID2)
    SetGadgetState(#Radio_0, 1)
    OptionGadget(#Radio_1,200,260,80,30," Random")
    SetGadgetFont(#Radio_1,FontID2)
  EndIf
  PureCOLOR_SetWindowColor(#Window_0,RGB(254,249,213))
  PureCOLOR_SetGadgetColor(#TrackBar_0,RGB(0,0,0),RGB(255,249,213))
  PureCOLOR_SetGadgetColor(#Radio_0, RGB(0,0,0),RGB(255,249,213))
  PureCOLOR_SetGadgetColor(#Radio_1, RGB(0,0,0),RGB(255,249,213))
  PureCOLOR_SetGadgetColor(#TrackBar_0,RGB(0,0,0),RGB(255,249,213))
  AddSysTrayIcon(#SysTrayIcon,WindowID(#Window_0),Image0)
Else
  MessageRequester("Problem","Window could not be opened.",#MB_ICONERROR)
EndIf


Last.b=-1 ;To avoid the use of the auto zero value.

Repeat 
  
  Event = WaitWindowEvent() 
  WindowID = EventWindow() 
  GadgetID = EventGadget() 
  EventType = EventType() 
  Slide.b = GetGadgetState(#TrackBar_0) 
    
  If Event = #PB_Event_Gadget
    
    If GadgetID = #Button_0
    
      If Radio.b=0:StopSound(-1):PlaySound(#Sound_0,0):EndIf
      
      If Radio=1
        
        Repeat
          Repeat 
            Kies.b=Random(3) 
            If Kies <> Last:Break:EndIf 
          ForEver ; After cycle of 4 randoms be sure it is not doubled when get nr. 5
          
          If Last<>-1:Last=-1:EndIf ; Value last played is only used once.
          
          If Kies=0 And Already0.b=0
            Already0=1
            Break
          EndIf
          If Kies=1 And Already1.b=0
            Already1=1
            Break
          EndIf
          If Kies=2 And Already2.b=0
            Already2=1
            Break
          EndIf
          If Kies=3 And Already3.b=0
            Already3=1
            Break
          EndIf
                
        ForEver
        
        If Already0=1 And Already1=1 And Already2=1 And Already3=1
          Already0=0
          Already1=0
          Already2=0
          Already3=0
          Last=Kies ; Stores the last played out of 4 randoms, to avoid double play.
        EndIf
        
        Select Kies
          Case 0
          StopSound(-1)
          PlaySound(#Sound_0,0)
          Case 1
          StopSound(-1)
          PlaySound(#Sound_1,0)
          Case 2
          StopSound(-1)
          PlaySound(#Sound_2,0)
          Case 3
          StopSound(-1)
          PlaySound(#Sound_3,0)
        EndSelect
        
      EndIf
      
    ElseIf GadgetID = #Radio_0
      Radio=0
    ElseIf GadgetID = #Radio_1
      Radio=1
    ElseIf GadgetID = #TrackBar_0
      If Slide=0
        PlaySound(#Sound_6,0)
      EndIf
      If Slide=1
        StopSound(-1)
        PlaySound(#Sound_4,0)
        MessageRequester("Hahaha!   version 0.4","Computer code by?"+Chr(13)+Chr(13)+"Character"+Chr(13)+Chr(13)+Chr(13)+"When?"+Chr(13)+Chr(13)+"September 2006"+Chr(13)+Chr(13)+Chr(13)+"Info?"+Chr(13)+Chr(13)+Chr(13)+Chr(13)+"Sounds?"+Chr(13)+Chr(13)+"www.meanrabbit.com")
      EndIf
      If Slide=2
        PlaySound(#Sound_6,0)
      EndIf
      
    EndIf
    
  EndIf
  
  If Event = #PB_Event_SysTray
    If EventType() = #PB_EventType_LeftClick
      SysTrayIconToolTip(EventGadget(), "Hahaha!")
      StopSound(#Sound_7)
      PlaySound(#Sound_7,0)
    EndIf
  EndIf  
  
Until Event = #PB_Event_CloseWindow 

StopSound(-1)
PlaySound(#Sound_5,0)
Delay(900)
CloseWindow(#Window_0)


If OpenWindow(#Window_0,477,385,300,300,"Hahaha!",#PB_Window_Invisible)
  AddSysTrayIcon(#SysTrayIcon,WindowID(#Window_0),Image0)
EndIf

Repeat
  Event=WindowEvent()
  If Event=#PB_Event_SysTray
    SysTrayIconToolTip(EventGadget(),"Hahaha! v0.4")
    If EventType()=#PB_EventType_RightClick
      BackValue=MessageRequester("Hahaha","STOP HAHAHA?",#PB_MessageRequester_YesNo|#MB_ICONQUESTION)
      If BackValue=#PB_MessageRequester_Yes : PlaySound(#Sound_6,0): End : EndIf
    EndIf
  EndIf
  Delay(50)
  Pick.w=Random(5000)
  If Pick=1000
    PlaySound(#Sound_6,0)
  EndIf
  If Pick=2000
    PlaySound(#Sound_4,0)
  EndIf
ForEver


;- Data Inclusion
DataSection 
Image0: 
  IncludeBinary "Graphics\Happy.ico"
EndDataSection


;- Mutex Close
CloseHandle_(MutexID)
End

Last edited by Character on Fri Jan 25, 2008 6:19 pm, edited 4 times in total.
Cessante causa cessat effectus
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Update

Post by ts-soft »

Character wrote: PS
Had some strange effects before compiling. Got a strange linker error.
When I unchecked the safethread option in the compiler it disappeared.
Anybody seen same problem?
The UserLib doesn't support threadsafe, so anybody have the same problem :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply