Jump to content

Countdown from tray that triggers something in exact time


noobish
 Share

Recommended Posts

Sorry to bother you again :)

I have this countdown script which i want to trigger n action in an exact time.

for example 2 hours before new year to pop up a png image with a message.

How to make to be only in tray and pop up a balloon with how many time is left for New Year.

Thank you in advance

#include 

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 122, 42, 438, 156)
$Label1 = GUICtrlCreateLabel("15:00", 8, 8, 43, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$time=TimerInit()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch

$new = TimerDiff ($time)
$new = (15*60*1000)-$new
$seconds = Round ($new/1000)
$newMin = Floor ($seconds/60)
$newSec = Mod ($seconds, 60)
If $newSec < 10 Then $newSec = "0"&$newSec
GUICtrlSetData ($Label1, $newMin&":"&$newSec)
WEnd
Link to comment
Share on other sites

PlayHD very nice what you done, but i want when i execute the script to show a baloon every 1 or 2 hours in systray for how many days/hours are left for new year. And 2 hours before new years to pop a message ie a greetings image or something

Thank you fo your help

Link to comment
Share on other sites

This is nice code by user UEZ, how i can make it to run only from a tray icon and popup a balloon every 2 hours ie. and give info of how many time is left until new year,

for example

23 days

556 hours

33378 minutes etc...

Because now it starts always from the start .

Any help my friends.

Thank you

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)
Global $msg, $label
Global $hGUI = GUICreate("Test", 300, 300) ; will create a dialog box that when displayed is centered
Global $button = GUICtrlCreateButton("YES", 10, 250, 50)
$label = GUICtrlCreateLabel("", 100, 120, 100, 30)
;~ GUICtrlSetBkColor(-1, 0x808080)
GUICtrlSetFont($label, 20, 400)
GUISetState() ; will display an empty dialog box

Global $countdown = 0.2 ;45 minutes
Global $seconds = $countdown * 60

Countdown()
AdlibRegister("Countdown", 1000)
Global $dummy = GUICtrlCreateDummy()
Do
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $button, $dummy
Run("calc.exe")
EndSwitch
Until False


AdlibUnRegister("Countdown")
GUIDelete($hGUI)
Exit

Func Countdown()
Local $sec, $min, $hr
$sec = Mod($seconds, 60)
$min = Mod($seconds / 60, 60)
$hr = Floor($seconds / 60 ^ 2)
GUICtrlSetData($label, StringFormat("%02i:%02i:%02i", $hr, $min, $sec))
$seconds -= 1
If $seconds < 0 Then
GUICtrlSendToDummy($dummy)
AdlibUnRegister("Countdown")
EndIf
EndFunc
Edited by noobish
Link to comment
Share on other sites

Try this:

#include <Date.au3>
#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)
Global $sTimeLeft,  $label
Global $hGUI = GUICreate("Test", 300, 300)
Global $button = GUICtrlCreateButton("YES", 10, 250, 50)
$label = GUICtrlCreateLabel("", 80,  120, 200, 30)
;~ GUICtrlSetBkColor(-1, 0x808080)
GUICtrlSetFont($label, 20, 400, 0, "Arial", 5)
GUISetState()

Global $seconds = _DateDiff("s", _NowCalc(), "2013/01/01 00:00:00")

Global $dummy = GUICtrlCreateDummy()
Countdown()
AdlibRegister("Countdown", 1000)

Global $iTimeTrayIcon = 2 * 60  * 60 * 1000 ;displays every 2h a tray tip
Global $iTimer = TimerInit()

Do
    Switch GUIGetMsg()
        Case  $GUI_EVENT_CLOSE
            ExitLoop
        Case $button, $dummy
            Run("calc.exe")
    EndSwitch
    If TimerDiff($iTimer) > $iTimeTrayIcon Then
        TrayTip("Information", "Sylvester Party in: " & $sTimeLeft, 10, 1)
        $iTimer = TimerInit()
    EndIf
Until False


AdlibUnRegister("Countdown")
GUIDelete($hGUI)
Exit

Func Countdown()
    Local $days = 0
    Local $sec = Mod($seconds, 60)
    Local $min = Mod(Int($seconds / 60), 60)
    Local $hr = Int($seconds / 60 ^ 2)
    If $hr > 23 Then
        $days = Floor($hr / 24)
        $hr -= $days * 24
    EndIf
    $sTimeLeft = StringFormat("%01id %02i:%02i:%02i", $days, $hr, $min, $sec)
    GUICtrlSetData($label, $sTimeLeft)
    $seconds -= 1
    If $seconds < 0 Then
        GUICtrlSendToDummy($dummy)
        AdlibUnRegister("Countdown")
    EndIf
EndFunc

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

noobish,

The following displays a countdown on a transparent gui and the same in a traytip every 30 seconds. The traytip stays active for 10 seconds. If you don't like the gui, comment it out.

You don't need this as a service to run automatically, just put it in the startup folder.

Calculations greedily plagarized from UEZ!!!

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

local $target_date  = '2013/01/01 00:00:00'
local $hrs, $mins, $secs, $days=0, $diff, $warn = 24*60*60, $warn_intrvl = 30, $display_time

local $gui010   =   guicreate('',@DesktopWidth,20,(@desktopwidth)/2,20,$ws_popup,bitor($ws_ex_layered,$ws_ex_topmost))
                    GUISetBkColor(0xABCDEF)
local $lbl010   =   guictrlcreatelabel('',0,0,600,20)
                    guictrlsetfont(-1,10,800,-1,'lucinda console')
                    _WinAPI_SetLayeredWindowAttributes($gui010, 0xABCDEF, 250)
                    guisetstate()

adlibregister('_update',1000)

while guigetmsg() <> $gui_event_close

wend

func _update()

    $diff = _datediff('s',_NowCalc(),$target_date)

    ; calcs from UEZ

    Local $secs = Mod($diff, 60)
    Local $mins = Mod(Int($diff / 60), 60)
    Local $hrs  = Int($diff / 60 ^ 2)
    If $hrs > 23 Then
        $days = Floor($hrs/ 24)
        $hrs -= $days * 24
    endif

    local $diff_out = stringformat('%02i Days %02i Hours %02i Minutes %02i Seconds to ' & stringleft($target_date,stringinstr($target_date,' ')), $days, $hrs, $mins, $secs)
    guictrlsetdata($lbl010,$diff_out)
    $warn -= 1
    if mod($warn,$warn_intrvl) = 0 then
        traytip('',$warn_intrvl & ' seconds have passed' & @lf & $diff_out,5)
        $display_time = 1
    endif
    if  $display_time = 10 then
        traytip('','',0)
        $display_time = 0
    endif
    if $display_time then $display_time += 1

endfunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Kylomas and UEZ what can i say guys,thank you very much,i'll change this to popup every 2 hours,and the colors a bit.

Only think is now to make it pop up a new eve image or better run something and install a wallpaper.

Whith a lot of shame,i am asking some help to this too.

Anyway God (or the spirits you believe in :) ) bless you all for the help you gave to me.

Link to comment
Share on other sites

noobish,

Take a look at "run","runwait", "shellexecute"...etc in the help file. As far as wallpaper goes, search the forum, I have no experience with this, but it cannot be that hard. You have everything you need in front of you.

Good Luck,

kylomas

edit: it looks like JLogan3o13 gave you the answer to wall paper

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...