News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Alarm clock

Started by jj2007, October 27, 2015, 12:12:09 PM

Previous topic - Next topic

jj2007

It should be self-explanatory...
include \masm32\MasmBasic\MasmBasic.inc
  SetGlobals OldTime$="?", hBigTime, Alarm$="?", AlarmOn=1, Sound$
  Init
  Enum IDGroup, IDSetStop, IDHms, IDHmsTxt, IDTime, IDTimer
  MakeFont hFont, Height:-18, "Arial"
  MakeFont hBigFont, Height:-48
  MakeBrush hRed, RgbCol(255, 200, 200)
  MakeBrush hGreen, RgbCol(200, 255, 200)
  Let Sound$=CL$() ; check if a sound file was passed via the command line
  .if !Exist(Sound$)
Let Sound$=ExpandEnv$("%WinDir%\Media\Windows Error.wav") ; no, go for a Windows sound then
  .endif
  DlgDefine "Alarm clock", 0, 0, 105, -4, WS_SYSMENU or DS_SYSMODAL or DS_CENTER or WS_MINIMIZEBOX, 12 ; x, y ignored, 105 wide, 4 lines, styles, font size 12
  DlgIcon IDI_APPLICATION ; OPT_Icon Timer
  DlgControl dcEdit, wfTime$(1), WS_BORDER or WS_TABSTOP, 7, 79.5, 44.0, 14, IDHms ; first control gets the focus
  DlgControl dcStatic, 0, SS_LEFTNOWORDWRAP, 2, 0, 110.0, 28, IDTime ; big text
  DlgControl dcButton, "Alarm", BS_GROUPBOX, 2, 60.0, 111.0, 62.0       ; 60.0 means 70%
  DlgControl dcButton, "Stop alarm", BS_PUSHBUTTON or WS_TABSTOP, 55.0, 79.5, 54.0, 14, IDSetStop
  DlgHandler MyHandler
  DlgShow
  Exit
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
MyHandler proc hDlg, uMsg, wParam, lParam
  SetGlobals
  .if uMsg==WM_INITDIALOG
For_ ct=IDGroup To IDHms
invoke SendMessage, rv(GetDlgItem, hDlg, ct), WM_SETFONT, hFont, 0
Next
mov hBigTime, rv(GetDlgItem, hDlg, IDTime)
invoke SendMessage, eax, WM_SETFONT, hBigFont, 0
invoke SetTimer, hDlg, IDTimer, 50, 0
  .elseif uMsg==WM_CTLCOLORSTATIC
.if lParam==rv(GetDlgItem, hDlg, IDTime)
invoke SetBkMode, wParam, TRANSPARENT
invoke SetBkColor, wParam, RgbCol(255, 255, 255)
mov eax, hRed
.if AlarmOn
mov eax, hGreen
.endif
mov [esi.MbDLG.dlgRetEax], eax
.endif
  .elseif uMsg==WM_COMMAND
.if wParam==IDSetStop
invoke GetDlgItem, hDlg, IDSetStop
.if AlarmOn
SetWin$ eax="Set Alarm"
Clr AlarmOn
.else
or AlarmOn, -1
SetWin$ eax="Stop Alarm"
.endif
.endif
  .elseif uMsg==WM_TIMER
.if StringsDiffer(Time$, OldTime$)
Let OldTime$=Time$
SetWin$ hBigTime=" "+Time$+" "
.if !StringsDiffer(OldTime$, Win$(hDlg, IDHms))
If_ AlarmOn Then ShEx Sound$, SW_MINIMIZE ; OPT_Arg1 beatles-let_it_be.mid
.endif
.endif
  .endif
  or eax, -1 ; continue processing
  ret
MyHandler endp
EndOfCode

dedndave

needs a notification area icon  :P

Grincheux

Why would it be on the title of each window. Like this it would be easy to have the date and time.

Magnum

My friend,

When I started the prog, the timer counts down.

It looks like the countdown is really a clock.

When I set an alarm, there was no sound when the time was reached.



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

OK, here is version 2 - it checks whether a sound file is present in the same folder.
Besides, it has a very useful +5 button, and an edit control for writing "call mom" or whatever.

Grincheux

It runs on my w10.
My last message always is available.
Nice job