Timer (gui) Alerts me when it's time

User projects written in or related to FreeBASIC.
enform
Posts: 172
Joined: Apr 24, 2011 12:57
Location: France

Timer (gui) Alerts me when it's time

Postby enform » Jan 12, 2019 21:56

Hello,

It's a little tool with :
- a window : light green at the beginning
- a trackbar 1 to 240 minutes
- 2 buttons Start & Stop
- 3 textboxes : minutes total,remaining,trackbar
- Checkbox : sound at the end or not
When Start get clicked , the window becomes yellow
At the end of time :
the window becomes a top window ,the window color changes to lite red , its size changes 5 times in 5 seconds
and finally a top MessageBox appears with a fine sound .
And voila !
Greetings

Code: Select all


    ' Timer
 
#Include Once "window9.bi"
 
Type w0
   As HWND hwnd_0
   As Long lGet,lGetOld,lGetTrack,lStartedFlag
   Declare Function OpenWindow_0() As HWND
   Declare Sub Sub_SelectedTime7( )  '  TrackBar  : 
   Declare Sub Sub_Start5( )  '  Button  :  Start
   Declare Sub Sub_Stop6( )  '  Button  :  Stop
End Type
 
' Dim
   Dim Shared As w0 win0
' End Dim
 
Function w0.OpenWindow_0() As HWND
   hwnd_0 = OpenWindow("Timer",10,400,190,300)
   WindowBounds(hwnd_0,170,280,210,320)
   WindowColor(hwnd_0,BGR(210,250,190))
   SetGadgetFont(,CInt(LoadFont("Courier New",10)))
   Var HIMAGE = Load_icon(ExePath + "\*.ico")
   SendMessage(hwnd_0,WM_SETICON,ICON_BIG,Cast(LPARAM,HIMAGE))
 
   TextGadget(1,10,10,70,15," Time max :")
   SetGadgetColor(1,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetFont(1,CInt(LoadFont("Tahoma",9)))
 
   TextGadget(2,30,30,40,20,"240")
   SetGadgetColor(2,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetFont(2,CInt(LoadFont("Tahoma",9)))
   
   TextGadget(3,10,65,70,15," Remaining :")
   SetGadgetColor(3,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetFont(3,CInt(LoadFont("Tahoma",9)))
   
   TextGadget(4,30,85,40,20,"Stop")
   SetGadgetColor(4,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetFont(4,CInt(LoadFont("Tahoma",11,0,1)))
 
   ButtonGadget(5,10,140,70,20,"Start")
   SetGadgetFont(5,CInt(LoadFont("Tahoma",9)))
 
   ButtonGadget(6,10,180,70,20,"Stop")
   SetGadgetFont(6,CInt(LoadFont("Tahoma",9)))
 
   CheckBoxGadget(9,10,220,70,20,"Sound")

   SetGadgetColor(9,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetState(9,1)
   
   TrackBarGadget(7,110,10,30,200,0,240,TBS_AUTOTICKS Or TBS_VERT) ' 0 to 240 minutes
   SetGadgetColor(7,BGR(150,220,240),BGR(0,180,0),3)
   
   TextGadget(8,100,220,45,20,"   "+GetGadgetText(4))
   SetGadgetColor(8,BGR(210,250,190),BGR(0,0,0),3)
   SetGadgetFont(8,CInt(LoadFont("Tahoma",9)))
 
   Return hwnd_0
End Function

 
win0.hwnd_0 = win0.OpenWindow_0()
 
 
Sub Decrease()
   win0.lGetTrack -= 1
   SetGadgetText(4,Str(win0.lGetTrack))
   If win0.lGetTrack < 1 Then
      SetWindowTop(win0.hwnd_0,1) ' topmost
      WindowColor(win0.hwnd_0,BGR(250,100,140))  ' red
      For r As Byte = 1 To 6   
           ' ResizeWindow  validate SetWindowTop !!!
         ResizeWindow(win0.hwnd_0,WindowX(win0.hwnd_0)-10,WindowY(win0.hwnd_0)-10,210,320)
         Sleep(300)
         ResizeWindow(win0.hwnd_0,WindowX(win0.hwnd_0)+10,WindowY(win0.hwnd_0)+10,190,300)
         Sleep(300)
      Next
      If win0.lStartedFlag Then
         KillTimer(win0.hwnd_0,1)
          MessBox("Time ellapsed !","Wake up !!!        ",MB_ICONWARNING  Or MB_TOPMOST)
         win0.Sub_Stop6( )
         If GetGadgetState(9) Then   
            PlaySound("SYSTEMEXCLAMATION",0,SND_ALIAS Or SND_SYNC)
         EndIf   
      EndIf
   EndIf
End Sub
 
Sub w0.Sub_SelectedTime7( )  '  TrackBar  :
   lGet = GetTrackBarPos(7)
   lGetTrack = 240-lGet
   If lStartedFlag = 0 And lGet <> lGetOld Then
      SetGadgetText(2,Str(lGetTrack))
      SetGadgetText(4,GetGadgetText(2))
      SetGadgetText(8,"   "+GetGadgetText(2))
   EndIf
   lGetOld = lGet
End Sub
 
Sub w0.Sub_Start5( )  '  Button  :  Start
   SetGadgetText(4,Str(lGetTrack))
   WindowColor(hwnd_0,BGR(250,230,125)) ' yellow
   SetTimer(hwnd_0,1,60000,Cast(Any Ptr,@ Decrease))
   lStartedFlag = 1
End Sub
 
Sub w0.Sub_Stop6( )  '  Button  :  Stop
   SetGadgetText(4,"Stop")
   KillTimer(hwnd_0,1)
   lStartedFlag = 0
   WindowColor(hwnd_0,BGR(210,250,190)) ' green
   SetWindowTop(hwnd_0,0)
End Sub
 
 
 
Do
   Var event = WaitEvent
   Select Case event
      Case EventClose
         Exit Do     ' End
      Case EventGadget
         Select Case EventNumber
            Case 7      '  TrackBar :
               win0.Sub_SelectedTime7( )
            Case 5      '  Button : Start
               win0.Sub_Start5( )
            Case 6      '  Button : Stop
               win0.Sub_Stop6( )
         End Select
   End Select
Loop
'

leopardpm
Posts: 1791
Joined: Feb 28, 2009 20:58

Re: Timer (gui) Alerts me when it's time

Postby leopardpm » Jan 12, 2019 23:34

what is window9.bi? doesnt run without it.....
VANYA
Posts: 1309
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Timer (gui) Alerts me when it's time

Postby VANYA » Jan 13, 2019 3:18

leopardpm wrote:what is window9.bi? doesnt run without it.....


Hi all!

viewtopic.php?f=14&t=17058
enform
Posts: 172
Joined: Apr 24, 2011 12:57
Location: France

Re: Timer (gui) Alerts me when it's time

Postby enform » Jan 13, 2019 10:16

Hi,

@leopardpm , where was you since 2010 , my friend ? window9.bi aka FbGui2 is one of the N best gui library
for Window . I use it with FbEdit with the addition of the 'api' file for the 'in line' help : if you need it tell us .
If you know PureBasic , you have an idea of the similar code .
Hi VANYA
Greetings
RNBW
Posts: 181
Joined: Apr 11, 2015 11:06
Location: UK

Re: Timer (gui) Alerts me when it's time

Postby RNBW » Jan 13, 2019 11:16

leopardpm wrote:what is window9.bi? doesnt run without it.....

Window9.bi is part of the FBGUI library for windows 2 found here https://www.freebasic.net/forum/viewtopic.php?f=14&t=17058. It is very similar to the Purebasic syntax and can be run in 32bit or 64 bit Freebasic.
There are lots of examples and it has a very good .chm help.

It is well worth while installing. I transfer the library's .bi files into Freebasic inc folder and its lib files into Freebasic's lib folders.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest