Author Topic: Alarm clock  (Read 1094 times)

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Alarm clock
« on: October 27, 2015, 12:12:09 PM »
It should be self-explanatory...
Code: [Select]
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

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Alarm clock
« Reply #1 on: October 28, 2015, 01:32:30 AM »
needs a notification area icon  :P

Grincheux

  • Member
  • ***
  • Posts: 328
  • Never be pleased, Always improve
    • Asm for fun
Re: Alarm clock
« Reply #2 on: December 18, 2015, 06:34:20 AM »
Why would it be on the title of each window. Like this it would be easy to have the date and time.
Kenavo (Bye)
----------------------
Asm for Fun
My Links
"La garde meurt mais ne rend pas"
Cambronne à Waterloo

Magnum

  • Member
  • *****
  • Posts: 2235
Re: Alarm clock
« Reply #3 on: December 18, 2015, 11:04:07 AM »
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-16.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

  • Member
  • *****
  • Posts: 7552
  • Assembler is fun ;-)
    • MasmBasic
Re: Alarm clock
« Reply #4 on: December 18, 2015, 05:18:36 PM »
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

  • Member
  • ***
  • Posts: 328
  • Never be pleased, Always improve
    • Asm for fun
Re: Alarm clock
« Reply #5 on: December 19, 2015, 12:38:39 AM »
It runs on my w10.
My last message always is available.
Nice job


Kenavo (Bye)
----------------------
Asm for Fun
My Links
"La garde meurt mais ne rend pas"
Cambronne à Waterloo