Jump to content

Reminder


Recommended Posts

This is a reminder for when to go wash the dishes. I am having trouble with the snooze button. How do you make it so once it's pressed, it'll remind again with the soundplay and GUI one minute later?

Thank you.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Alert", 178, 67, 394, 413)
GUISetFont(8, 800, 0, "Times New Roman")
$Label1 = GUICtrlCreateLabel("Go wash the dishes!", 24, 0, 127, 23)
GUICtrlSetFont(-1, 12, 800, 2, "Adobe Garamond Pro Bold")
$Snooze = GUICtrlCreateButton("Snooze", 8, 32, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")
GUICtrlSetBkColor(-1, 0xFF0000)
$Ok = GUICtrlCreateButton("Ok!", 96, 32, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")
GUICtrlSetBkColor(-1, 0x01A712)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

Global $Hour
Global $Min
Global $Sec

While 1
    if @HOUR = 14 and @MIN = 40 Then
        SoundPlay(@WindowsDir & "media\notify.wav", 0)
        GUISetState(@SW_SHOW)
    EndIf
    
    if @Hour = 20 and @MIN = 40 Then
        SoundPlay(@WindowsDir & "media\notify.wav", 0)
        GUISetState(@SW_SHOW)
    EndIf
    
    if @Hour = $Hour and @Min = $Min and @SEC = $Sec Then
        SoundPlay(@WindowsDir & "media\notify.wav", 0)
        GUISetState(@SW_SHOW)
    EndIf
    
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Snooze
    ;Remind in 1 minute
            GUISetState(@SW_Hide)
            $Hour = @HOUR
            $Min = @MIN + 1
            $Sec = @SEC
            
        Case $Ok
    ;Turns off the reminder for this session
            GUISetState(@SW_Hide)
            Sleep(60000)
    EndSwitch
WEnd
Edited by lbrtdy
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Alert", 178, 67, 394, 413)
GUISetFont(8, 800, 0, "Times New Roman")
$Label1 = GUICtrlCreateLabel("Go wash the dishes!", 24, 0, 127, 23)
GUICtrlSetFont(-1, 12, 800, 2, "Adobe Garamond Pro Bold")
$Snooze = GUICtrlCreateButton("Snooze", 8, 32, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")
GUICtrlSetBkColor(-1, 0xFF0000)
$Ok = GUICtrlCreateButton("Ok!", 96, 32, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman")
GUICtrlSetBkColor(-1, 0x01A712)
GUISetState()

Global $Hour = 0
Global $Min = 0
Global $Sec = 0
Global $iDelay = 0

While 1
    Select
        Case @HOUR = 14 And @MIN = 40
            SoundPlay(@WindowsDir & "\media\notify.wav", 0)
            GUISetState()
    
        Case @Hour = 20 And @MIN = 40
            SoundPlay(@WindowsDir & "\media\notify.wav", 0)
            GUISetState()
    EndSelect
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Snooze
    ;Remind in 1 minute
            GUISetState(@SW_HIDE)
            AdlibEnable('_Sleep', 1000)
            
        Case $Ok
    ;Turns off the reminder for this session
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd
GUIDelete()
Exit

Func _Sleep()
    $iDelay += 1
    If $iDelay = 60 Then
        $iDelay = 0
        SoundPlay(@WindowsDir & "\media\notify.wav", 0)
        GUISetState()
        AdlibDisable()
    EndIf
EndFunc

Link to comment
Share on other sites

wow your script works as a charm, thank you very much! :) But I have a few questions. I noticed that the alarm would continue to sound regardless if I push ok or snooze as long as it's on the same minute so I added

.... and @sec = 00 then
....

Which seems to do the trick, but how reliable is this? Does the While 1 loop check the time often enough so it won't miss this 1 second and miss the alarm?

My second question is that I noticed you removed a lot of the #includes that Koda GUI maker added in, why is that? Are those not essential?

Edit: My third question is that I notice the GUI seems to remember the last location and pop up in that location. How do you make it so it pops up centered on the monitor every time?

Well thanks for your effort, much appreciated :)

Edited by lbrtdy
Link to comment
Share on other sites

If you want to stop the current playing sound just call it like SoundPlay(''), and read the help file. :)

The things that was added by Koda Form Designer are pretty good and you should keep them, but because it's just an example and you are not using any SS_* or BS_* styles you don't need to include them. Same for a #Region - #EndRegion block, if you don't need the readability you can drop them.

The window position is changed only by setting it's x, y, width or height attributes, to center the window you need just the width and height of the desktop and the window so it'll be:

$aPos = WinGetPos($hGUI)
WinMove($hGUI, '', @DesktopWidth/2-$aPos[2]/2, @DesktopHeight/2-$aPos[3]/2);, $aPos[2], $aPos[3])

Read the help file for WinGetPos() and WinMove() functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...