AutoHotkey Community

It is currently May 27th, 2012, 6:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Countdown timer app
PostPosted: August 31st, 2010, 10:14 pm 
Offline

Joined: February 3rd, 2010, 12:47 pm
Posts: 38
Location: Zagreb, Croatia
Hi everybody,
recently I'm having a lot of free time while on work so I keep looking at my watch and calculate how much longer I have to stay there before I go home.
Therefore I searched a few older treads on Countdown timers and this is the result:
Code:
/*
Countdown 1.0 aka How long till I go home?
by Bekihito, WTFPL licence (http://en.wikipedia.org/wiki/WTFPL)
many thanks to the authors  and contributors of http://www.autohotkey.com/forum/viewtopic.php?t=19740&highlight=countdown
for inspiration and help with this variant
*/

SetBatchLines, -1
#SingleInstance, Force
#NoEnv
SetWorkingDir , %A_ScriptDir%
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

if (FileExist("CountSet.ini")){
    IniRead , XPos, CountSet.ini, Position, XPosition,
    IniRead , YPos, CountSet.ini, Position, YPosition,
    IniRead , Message, CountSet.ini, User, Message
    IniRead , StartTime, CountSet.ini, User, StartTime
    IniRead , EndTime, CountSet.ini, User, EndTime
    }Else{
        XPos := XI/2
        YPOs := YI/2
        Message = "Time to go!!!"
    }

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)
CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, NoStandard
Menu,Tray, Add, EndTime, SetClock
Menu,Tray, Add, Period, SetPeriod
Menu,Tray, Add,
Menu,Tray, Add, Message, SetMessage
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):

SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.

Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

Return  ; // End of Auto-Execute Section


UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    MsgBox,,Done, %Message%
    }
Return

SetClock: ;Input the goal time -in my case the time I get of work,but you could type e.g. X-mass
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox , Date, Set Date ,YYYYMMDD,,160,120, %XInput%, %YInput%,,, %A_YEAR%%A_MM%%A_DD%
InputBox ,Goal ,Set EndTime,HHmm,,160 ,120, %XInput%, %YInput%,,,HHmm
Emsec = 00
StartTime = %A_Now%
EndTime = %Date%%Goal%%Emsec%
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetPeriod: ; Input any given time period like DDDHHmm = 0010101 = 1day 1hour 1minutes for fancy egg timer function
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox ,Period ,Set Period,DDDHHmm,,160 ,120, %XInput%, %YInput%,,,DDDHHmm
StringMid ,PeriodD, Period,1, 3
StringMid ,PeriodH, Period,4, 2
StringMid ,Periodm, Period,6, 2
Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
StartTime = %A_Now%
EndTime = %A_Now%
EnvAdd EndTime, Periodsec, seconds
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetMessage: ;Input custom message that will popup when the timer gets to 00:00:00
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
InputBox ,Message, Set Message, Custom message: ,,160 ,120, %XInput%, %YInput%,,,%Message%
Return

GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
WinGetPos ,XPos ,YPos,,,Time-to-Go
IniWrite , %XPos%, %A_ScriptDir%\CountSet.ini, Position, XPosition
IniWrite , %YPos%, %A_ScriptDir%\CountSet.ini, Position, YPosition
IniWrite , %Message%, %A_ScriptDir%\CountSet.ini, User, Message
IniWrite , %StartTime%, %A_ScriptDir%\CountSet.ini, User, StartTime
IniWrite , %EndTime%, %A_ScriptDir%\CountSet.ini, User, EndTime
ExitApp

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}

Hope you like it!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2010, 11:30 pm 
Offline

Joined: June 8th, 2009, 8:09 pm
Posts: 84
neat little timer with resume after close, many thanks will be very handy!

one question about modding - how to add buttons for start/end time on the main GUI instead of the tray menu?

merci :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 2:59 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Here is a much more direct way to put seconds in h:mm:ss format
Code:
FormatSeconds(x)
{
Loop 2 ;make it base 60 with : divider Sec and Min
  Out:=SubStr("0" . Mod(x, 60),-1) ":" Out,x:=Floor(x/60)
Out:=x ":" Out ;put hours on front
Return SubStr(Out,1,-1) ;remove extra :
}
Will still work if you put in 1000 hours worth of seconds


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 7:38 am 
Offline

Joined: February 3rd, 2010, 12:47 pm
Posts: 38
Location: Zagreb, Croatia
Bebert wrote:
neat little timer with resume after close, many thanks will be very handy!

one question about modding - how to add buttons for start/end time on the main GUI instead of the tray menu?

merci :)

I'm glad you like it. If you wish to have the menu items inside the window add this piece of code after the Tray menu lines (around line 38 or anywhere before GUI, Show)
Code:
;To Place a Menu bar with options into the window
Menu,Settings, Add, EndTime, SetClock
Menu,Settings, Add, Period, SetPeriod
Menu,Settings, Add, Message, SetMessage
Menu, Bar, Add, Set, :Settings
Menu,Bar, Add, Exit, GuiClose
;Menu,Bar, Color, %CustomColor% ;uncomment if you wish to have the same transparency look and feel, but less viewable
Gui , Menu, Bar

Or if you want something else check the Menu command in the documentation.
However, I leave up to you to place the Input boxes (where they popup ) in a better place ;-). Now they are (more or less) near the Tray icon.

To @none: I know that perhaps there are better ways to do this entirely, but as I stated in the precomment it is a product of few older treads (specifically the part of code you mention is from the AHK documentation FORMATTIME examples) but feel free to improve/change anything.
BR


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2010, 9:44 am 
Offline

Joined: June 8th, 2009, 8:09 pm
Posts: 84
thanks bekihito.

I actually made a couple of main GUI buttons with gEndTime and gPeriod - works also.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Countdown with soundplay
PostPosted: October 15th, 2010, 2:27 pm 
Greetings,
I want the counter to plan a sound to remind me, so i modified the code as :

Code:
/*
Countdown 1.0 aka How long till I go home?
by Bekihito, WTFPL licence (http://en.wikipedia.org/wiki/WTFPL)
many thanks to the authors  and contributors of http://www.autohotkey.com/forum/viewtopic.php?t=19740&highlight=countdown
for inspiration and help with this variant
*/

SetBatchLines, -1
#SingleInstance, Force
#NoEnv
SetWorkingDir , %A_ScriptDir%
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

if (FileExist("CountSet.ini")){
    IniRead , XPos, CountSet.ini, Position, XPosition,
    IniRead , YPos, CountSet.ini, Position, YPosition,
    IniRead , Message, CountSet.ini, User, Message
    IniRead , StartTime, CountSet.ini, User, StartTime
    IniRead , EndTime, CountSet.ini, User, EndTime
    }Else{
        XPos := XI/2
        YPOs := YI/2
        Message = "Time to go!!!"
    }

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)
CustomColor = C0C0C0 ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, NoStandard
Menu,Tray, Add, EndTime, SetClock
Menu,Tray, Add, Period, SetPeriod
Menu,Tray, Add,
Menu,Tray, Add, Message, SetMessage
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):

SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.

Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

Return  ; // End of Auto-Execute Section


UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    SoundPlay, d:\frantic.wav
    ;sgBox,,Done, %Message%
    }
Return

SetClock: ;Input the goal time -in my case the time I get of work,but you could type e.g. X-mass
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox , Date, Set Date ,YYYYMMDD,,160,120, %XInput%, %YInput%,,, %A_YEAR%%A_MM%%A_DD%
InputBox ,Goal ,Set EndTime,HHmm,,160 ,120, %XInput%, %YInput%,,,HHmm
Emsec = 00
StartTime = %A_Now%
EndTime = %Date%%Goal%%Emsec%
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetPeriod: ; Input any given time period like DDDHHmm = 0010101 = 1day 1hour 1minutes for fancy egg timer function
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox ,Period ,Set Period,DDDHHmm,,160 ,120, %XInput%, %YInput%,,,DDDHHmm
StringMid ,PeriodD, Period,1, 3
StringMid ,PeriodH, Period,4, 2
StringMid ,Periodm, Period,6, 2
Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
StartTime = %A_Now%
EndTime = %A_Now%
EnvAdd EndTime, Periodsec, seconds
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetMessage: ;Input custom message that will popup when the timer gets to 00:00:00
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
InputBox ,Message, Set Message, Custom message: ,,160 ,120, %XInput%, %YInput%,,,%Message%
Return

GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
WinGetPos ,XPos ,YPos,,,Time-to-Go
IniWrite , %XPos%, %A_ScriptDir%\CountSet.ini, Position, XPosition
IniWrite , %YPos%, %A_ScriptDir%\CountSet.ini, Position, YPosition
IniWrite , %Message%, %A_ScriptDir%\CountSet.ini, User, Message
IniWrite , %StartTime%, %A_ScriptDir%\CountSet.ini, User, StartTime
IniWrite , %EndTime%, %A_ScriptDir%\CountSet.ini, User, EndTime
ExitApp

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}


This works for me. You can customize the wav sound as a crazy woman/man scream or a simple ring tone, or a beep or likewise.

Cheers
-pop


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2010, 11:05 am 
Offline

Joined: April 30th, 2009, 12:35 pm
Posts: 29
Here's my contribution based on tic's GDI+

Code:
#SingleInstance,Ignore
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

   DetectHiddenWindows On
   
; Start gdi+
   If !pToken := Gdip_Startup()
   {
      MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
      GoSub,GUIClose
   }

;---------------------------------------

   Menu,Tray,NoStandard
   Menu,Tray,DeleteAll
   Menu,Tray,Add,Exit,GuiClose

;Change this based on when you want to countdown to
   EndTime := 20101228140000

   Font = Arial
   Size = 36
   Style = Regular
   SAlign = Left
   SvPos = Bottom
   Transparancy = 255
   Vtolerance = -30
   Htolerance = 0
   Colour = ffffff
   Border = 3
   BColour = 000000

   Settimer,Preview_PNG,1000

Return

;---------------------------------------

GUIClose:

; gdi+ may now be shutdown on exiting the program
   Gdip_Shutdown(pToken)
   
   ExitApp

Return

;---------------------------------------

Preview_PNG:

   mysec := EndTime
   EnvSub, mysec, %A_Now%, seconds

   if mysec < 7200
      Colour = ffff00
   if mysec < 3600
      Colour = ff0000
   if mysec < 0
      GoSub,GUIClose
      
   Text = % "Countdown : " . FormatSeconds( mysec )

;-- Build temporary window to determine maximum width
   Gui 3:-Caption
   gui 3:Margin,0,0
   gui 3:Font,s%Size%,%Font%
   gui 3:Add,Text,,%Text%
   gui 3:Show,Hide  ;-- Render but don't show   

;-- How wide is it?
   gui 3:+LastFound
   WinGetPos ,,,Width,Height,% "ahk_id " . WinExist()
   gui 3:Destroy
   
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
   Gui, 4: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
   Gui, 4: Show, NA

; Get a handle to this window we have created in order to update it later
   hwnd1 := WinExist()

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
   hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)

; Get a device context compatible with the screen
   hdc := CreateCompatibleDC()

; Select the bitmap into the device context
   obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
   G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
   Gdip_SetSmoothingMode(G, 4)

   WriteText(G, Text, Size, Align, vPos, Font, Colour, Transparancy, Style, Border, BColour,  Width, Height)

   if SAlign = Left
   {
      TextToImage_X := 0 + Htolerance
   }
   if SAlign = Centre
   {
      TextToImage_X := ((A_ScreenWidth - Width) // 2) + Htolerance
   }
   if SAlign = Right
   {
      TextToImage_X := A_ScreenWidth - Width + Htolerance
   }
   if SvPos = Top
   {
      TextToImage_Y := 0 + Vtolerance
   }
   if SvPos = vCentre
   {
      TextToImage_Y := ((A_ScreenHeight - Height) // 2) + Vtolerance
   }
   if SvPos = Bottom
   {
      TextToImage_Y := A_ScreenHeight - Height + Vtolerance
   }

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
   UpdateLayeredWindow(hwnd1, hdc, TextToImage_X, TextToImage_Y, Width, Height)

; Select the object back into the hdc
   SelectObject(hdc, obm)

; Now the bitmap may be deleted
   DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
   DeleteDC(hdc)

Return

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
   FormatTime, mm, %time%, mm
   FormatTime, ss, %time%, ss
   days := NumberOfSeconds // (3600 * 24)
   hours := (NumberOfSeconds // 3600) - (days * 24)
    return days " days, " hours " hours, " mm " minutes, " ss " seconds"
}

WriteText(G="", Text="TextToImage", Size="20", Align="Bottom|Centre", vPos="Top", Font="Arial", Colour="ffffff", Transparancy="ff", Style="", Border="0", BColour="000000",  Width="", Height="")
{
   SetFormat, integer, hex
   Transparancy := Transparancy
   SetFormat, integer, d

   Gdip_GraphicsClear(G, 0x00ffffff)
   Gdip_SetInterpolationMode(G,7)   
   pPath := Gdip_CreatePath(0)
   Options = w%Width% h%Height% %Align% s%Size% %Style%
   Gdip_AddString(pPath, Text, Font, Options)
   if Border > 0
   {
      pPen := Gdip_CreatePen(Transparancy . BColour, Border)
      Gdip_SetLineJoin(pPen)
      Gdip_DrawPath(G, pPen, pPath)
      Gdip_DeletePen(pPen)
   }
   pBrush := Gdip_BrushCreateSolid(Transparancy . Colour)
   Gdip_FillPath(G, pBrush, pPath)
   Gdip_DeleteBrush(pBrush)
   Gdip_DeletePath(pPath)
}

Gdip_AddString(Path, sString,fontName, options,stringFormat=0x4000)
{
   nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
   VarSetCapacity(wString, nSize*2)
   DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)

   hFamily := Gdip_FontFamilyCreate(fontName)
   RegExMatch(Options, "i)X([\-0-9]+)", xpos)
   RegExMatch(Options, "i)Y([\-0-9]+)", ypos)
   RegExMatch(Options, "i)W([0-9]+)", Width)
   RegExMatch(Options, "i)H([0-9]+)", Height)
   RegExMatch(Options, "i)R([0-9])", Rendering)   
      
   Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
   Loop, Parse, Styles, |
   {
      If RegExMatch(Options, "i)\b" A_loopField)
      Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
   }
   RegExMatch(Options, "i)S([0-9]+)", fontSize)
   Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
   Loop, Parse, Alignments, |
   {
      If RegExMatch(Options, "i)\b" A_loopField)
      Align |= A_Index//2.1      ; 0|0|1|1|2|2
   }
   hFormat := Gdip_StringFormatCreate(stringFormat)
   Gdip_SetStringFormatAlign(hFormat, Align)   
   Gdip_SetTextRenderingHint(pGraphics, Rendering)
   CreateRectF(textbox, xpos1, ypos1, Width1, Height1)   
   iRet := DllCall("gdiplus\GdipAddPathString", "UInt", Path,  "UInt", &wString, "Int", -1, "Uint",hFamily, "Int", Style, "Float", fontSize1,"UInt", &textbox, "UInt", hFormat)
   Gdip_DeleteFontFamily(hFamily)
   Gdip_DeleteStringFormat(hFormat)
   return iRet          
}

Gdip_DrawPath(pGraphics, pPen, Path)
{
   return DllCall("gdiplus\GdipDrawPath", "UInt", pGraphics, "UInt", pPen, "UInt", Path)
}

Gdip_SetLineJoin(pPen, linejoin=2) ;LineJoinMiter = 0,LineJoinBevel = 1,LineJoinRound = 2,LineJoinMiterClipped = 3
{
   return DllCall("gdiplus\GdipSetPenLineJoin", "Uint", pPen, "uInt", linejoin)
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2010, 4:02 am 
Offline

Joined: December 30th, 2010, 3:53 am
Posts: 1
This script is very close to what I have been looking for. I have been able to modify it to suit my needes except for one thing. I am unable to run it in conjunction with I have been writing.

I have a script that I am writing where I use a loop to one-by-one connect to a remote computer with a program, download some log files and do some file moving. The reason I am looking for a timer is that the download time for the logs can take about 5-10 minutes and it would be nice to display this to the end user.

I don't have the exact code with me (it's on my work computer), but what I have looks something like:

-Start loop
-Open My program
-Do some repetitive keypresses/mous clicks to start log download
*START TIMER W/ GUI HERE
-Wait for 5 minutes
-When timer is done carry on with the next instance of the loop, rinse and repeat

Is there some way for this script to be integrated (function calls are something)?

EDIT:

Figured it out. For anyone who wants to modify this script to control the timing of a loop, see code below.

I removed the need for an ini file, gave a static Period (didn't need a clock feature), closed the GUI when not actively counting. It is a little resource intense, but works well enough for my needs.
Code:
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

XPos := XI/2
YPOs := YI/2
Message = "Log download complete"

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)


CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, Add
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00


Loop, 3
{
    MsgBox, Iteration number is %A_Index%.  ; A_Index will be 1, 2, then 3
    Sleep, 1000

   SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
   Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

   Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
   WinGetPos ,XPos ,YPos,,,Time-to-Go,
   Period = 0000001 ;Specified a known static Period (1 minute for testing purposes
   StringMid ,PeriodD, Period,1, 3
   StringMid ,PeriodH, Period,4, 2
   StringMid ,Periodm, Period,6, 2
   Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
   StartTime = %A_Now%
   EndTime = %A_Now%
   EnvAdd EndTime, Periodsec, seconds
   EnvSub StartTime, EndTime, seconds
   StartTime := Abs(StartTime)

   perc := 0 ;Resets percentage to 0, otherwise this loop never sees the counter reset
   Loop
   {
       if perc = 100
           break  ; Terminate the loop
       else
           continue ; Skip the below and start a new iteration
   }
    MsgBox, Loop %A_Index% is ended
    Gui, Cancel
}

UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    Gui, Cancel
    }
Return


GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
ExitApp


FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2011, 7:53 pm 
Offline

Joined: April 14th, 2011, 1:44 pm
Posts: 3
Sweeet 8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: GUI error
PostPosted: November 22nd, 2011, 5:43 am 
hello

for me when i compile this file, a window is showing with list of errors and saying that the thread will be exitted, but the code is still running and when i right click on the Hky icon is is asking start time, end time message etc, where can i see how many minutes elapsed etc.. is there something wrong with my installation?

can u help me out from this.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2011, 9:21 pm 
Offline

Joined: February 3rd, 2010, 12:47 pm
Posts: 38
Location: Zagreb, Croatia
dear naveen kumar,
are you using the new AHK_L or vanila AHK - it is made for vanila AHK.
here is the precompiled version that works fine on my XPSP3 and WIN7 computers:
http://www.autohotkey.net/~bekihito/countdown/Countdown.exe
BR


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: JamixZol, rbrtryn, Stigg and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group