Simple Countdown Timer in Gui?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Simple Countdown Timer in Gui?

18 Dec 2017, 21:22

How difficult does this need to be??

I've written some scripts to perform various tasks here and there that are timed (several over 1.5 hours), and I would like to display how much time is left during each task, and only during each task (based on time of day and day of week). I have Googled and found NUMEROUS and NUMEROUS examples all over Googleland, but nothing quite like what I'm looking for (on the surface anyway... too many to look deeply into).

I keep getting caught up with the conversions when trying to tailor them to my purpose, and I just have to ask, "How difficult does this need to be?"

My scripts timing is based on 'sleep (x number of milliseconds)' before the next task / function is to start.

How do I convert that into a Countdown Timer displayed in a GUI as a topmost window (hh:mm:ss), possibly showing the current time in the same window?

I've looked at:

https://autohotkey.com/board/topic/86297-countdown/
https://autohotkey.com/board/topic/4470 ... y-seconds/
https://autohotkey.com/board/topic/1130 ... own-timer/
https://autohotkey.com/board/topic/5315 ... ton-press/
https://autohotkey.com/board/topic/3265 ... -in-a-gui/
https://autohotkey.com/board/topic/3003 ... own-timer/
https://autohotkey.com/board/topic/1967 ... wn-script/
https://autohotkey.com/board/topic/5746 ... timer-app/
https://autohotkey.com/board/topic/9643 ... -shutdown/ (the last entry as a tooltip counter)
https://autohotkey.com/board/topic/6638 ... r-utility/ (this one has some nice tools, but far too complicated for what I'm looking for)
https://autohotkey.com/board/topic/7521 ... p-command/
https://autohotkey.com/board/topic/3578 ... e-help-gt/ (mind blown too much now to even get this one)
https://autohotkey.com/board/topic/5191 ... s-bar-gui/ (I like the progress bar, but have seen a better example elsewhere)
https://autohotkey.com/board/topic/8478 ... wn-button/
https://autohotkey.com/board/topic/5746 ... timer-app/ (this one is way cool, but again, pretty complicated with a systray interface, but might be the best to learn from)
https://autohotkey.com/board/topic/1815 ... ntry118754 (this is the one that seemed to be the most promising, but can't get the conversion set right)

There are probably hundreds more, but...
https://autohotkey.com/board/topic/1815 ... ntry118827 (this is one that I'll probably go with if I can figure out a way to work with YYYYMMDDHH24MISS formatting, which is what brings me here to ask, "WHY DOES IT NEED TO BE SO FRICKIN' COMPLICATED!?! lol)
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Simple Countdown Timer in Gui?

18 Dec 2017, 21:40

not sure if this will be helpful, but it does do a few of the things you are looking to do.

Code: Select all

;Writtn By: Hellbent aka CivReborn
;Written for: CivReborn Youtube Channel- https://www.youtube.com/user/CivReborn
;Date Written: Nov 26th, 2017
;Paste: https://pastebin.com/HxgmZVXF
#SingleInstance,Force
global StopWatch_State:=0,Pauseit:=0,Sound_Setting:=1,Tx:=600,Ty:=100,myHour:=A_Hour,Alarm_Off:=0,colour_List:= ["Lime","Yellow","Red"],lnum:=1
FormatTime, Time1,h , h tt
StringRight,time2,time1,2
myHour>=13?myHour-=12:myHour<1?myHour+=12
Clock_Gui()
SetTimer,Main_Clock,1000
return
Turn_Off_Alarm:
	Alarm_Off:=1
	return
Watch_Alarm:
	New_Second:=(A_TickCount-Alarm_Tick)//1000
	if(New_Second>Last_Second){
		Last_Second:=New_Second
		GuiControl,1:,Alarm_Progress,% Last_Second
		update_edit3_1:=(Alarm_Seconds-Last_Second)//60,update_edit3_2:=(Alarm_Seconds-Last_Second)-(update_edit3_1*60),update_Edit3_1<10?update_edit3_1:="0" update_edit3_1,update_Edit3_2<10?update_edit3_2:="0" update_edit3_2
		GuiControl,3:,edit3,% update_edit3_1 " : " update_edit3_2
	}
	if(Last_Second>=Alarm_Seconds){
		if(Sound_Setting=1){
			SetTimer,Watch_Alarm,Off
			Gui,1:Show
			Gui,4:Destroy
			while(!GetKeyState("RButton"))
				SoundBeep,850,500
			GuiControl,1:,Alarm_Progress,0
		}else if(Sound_Setting=2){
				SetTimer,Watch_Alarm,Off
				Gui,1:Show
				Gui,4:Destroy
				Flashing()
				while(Alarm_Off=0){
					Gui,5:Color,% colour_List[lnum]
					lnum++
					(lnum=4)?(lnum:=1)
					sleep,500
				}
			GuiControl,1:,Alarm_Progress,0
			Gui,5:Destroy
		}else if(Sound_Setting=3){
			SetTimer,Watch_Alarm,Off
			Gui,1:Show
			Gui,4:Destroy
			Flashing()
			while(Alarm_Off=0&&!GetKeyState("RButton")){
				Gui,5:Color,% colour_List[lnum]
				lnum++
				(lnum=4)?(lnum:=1)
				SoundBeep,850,500
			}
			GuiControl,1:,Alarm_Progress,0
			Gui,5:Destroy
		}
	}
	return
Set_Alarm_Time:
	if(Time_Radio=1)
		Alarm_Seconds:=3600
	else if(Time_Radio=2)
		Alarm_Seconds:=(Min_Slide*60)+Sec_Slide
	GuiControl,1:+Range0-%Alarm_Seconds%,Alarm_Progress
	GuiControl,1:,Alarm_Progress,0
	Last_Second:=0,Alarm_Tick:=A_TickCount,Alarm_Off:=0
	SetTimer,Watch_Alarm,333
	Gui,3:Destroy
	return
Cancel:
	Gui,3:Destroy
	return
Submit_All:
	Gui,3:Submit,NoHide
	GuiControl,3:,edit1,% Min_Slide
	GuiControl,3:,edit2,% Sec_Slide
	if(Time_Radio=1)
		GuiControl,3:,edit3,60 : 00
	else
		GuiControl,3:,edit3,% Min_Slide " : " Sec_Slide
	return
Reset:
	Gui,3:Destroy
	SetTimer,Watch_Alarm,Off
	GuiControl,1:,Alarm_Progress,0
	return
set_Alarm:
	Gui,3:Destroy
	Gui,3:+AlwaysOnTop -Caption +Owner1 +Border
	Gui,3:Color,0x72B4B1
	Gui_Control_Types := ["Radio","Radio","Groupbox","Text","Slider","Edit","Groupbox","Text","Slider","Edit","Groupbox","Edit","Groupbox","Button","Button","Button"]
	Control_Text:= ["1 Hour","Set Amount",Fake_Value,"Mins:",Fake_Value,Fake_Value,Fake_Value,"Secs:",Fake_Value,Fake_Value,Fake_Value,"60 : 00",Fake_Value,"Set","Reset","Back"],Fake_Value:=""
	for k, v in ["x10 y10 Checked vTime_Radio gSubmit_All","x100 y10 gSubmit_All","x10 y30 w200 h60 Section","xs+10 ys+20 w30,Mins:","x+10 w100 Range0-59 AltSubmit vMin_Slide gSubmit_All","x+10 w30 Center ReadOnly -E0x200 vedit1","x10 y100 w200 h60 Section","xs+10 ys+20 w30","x+10 w100 Range0-59 AltSubmit vSec_Slide gSubmit_All","x+10 w30 Center ReadOnly -E0x200 vedit2","x10 y160 w200 h40 Section","xs+10 ys+13 w180 h20 ReadOnly Center -E0x200 vedit3","x10 y200 w200 h40 Section","xs+10 ys+13 w50 h20 gSet_Alarm_Time","x+15 ys+13 w50 h20 gReset","x+15 ys+13 w50 h20 gCancel"]
		Gui,3:Add,% Gui_Control_Types[A_Index],% v ,% Control_Text[A_Index]
	gosub,Submit_All
	Gui,3:Show,AutoSize ,Alarm Setup
	return
Show_StopWatch:
	GuiControl,1:Hide,Main_Clock_Time
	GuiControl,1:Show,Stop_Watch
	Loop 6
		GuiControl,1:Show,SW%A_Index%
	Loop 3
		GuiControl,2:Show,% "SW" A_Index+6
	return
Show_Clock:
	GuiControl,1:Hide,Stop_Watch
	Loop 6
		GuiControl,1:Hide,SW%A_Index%
	Loop 3
		GuiControl,2:Hide,% "SW" A_Index+6
	GuiControl,1:Show,Main_Clock_Time	
	return	
Start_StopWatch:
	if(StopWatch_State=0){
		StopWatch_State:=1,Pauseit:=0,Start_Tick:=A_TickCount
		SetTimer,StopWatch_Timer,10
	}
	return
Pause_StopWatch:
	if(StopWatch_State=1)
		Pauseit:=!Pauseit,Start_Tick:=A_TickCount-Start_Tick
	return
Reset_StopWatch:
	StopWatch_State:=0
	Pauseit:=0
	SetTimer,StopWatch_Timer,Off
	GuiControl,1:,Stop_Watch, 000 : 00 : 00 : 000
	return
StopWatch_Timer:
	Stop_Hour:=((A_TickCount-Start_Tick)//3600000) 
	Stop_Min:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000))//60000) 
	Stop_Sec:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000)-(Stop_Min*60000))//1000) 
	Stop_MS:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000)-(Stop_Min*60000)-(Stop_Sec*1000)))
	Stop_Hour<10?Stop_Hour:="00" Stop_Hour
	Stop_Min<10?Stop_Min:="0" Stop_Min
	Stop_Sec<10?Stop_Sec:="0" Stop_Sec
	Stop_MS<100?Stop_MS:="0" Stop_MS
	if(Pauseit=0)
	GuiControl,1:,Stop_Watch,% Stop_Hour " : " Stop_Min " : " Stop_Sec " : " Stop_Ms 
	return
GuiClose:
	ExitApp
Sounds:
	Sound_Setting++
	Sound_Setting>=4?Sound_Setting:=1
	(Sound_Setting=1)?(HList:=["1:Show","1:Show","1:Show","1:Show","1:Hide","1:Hide","1:Hide"])
	:(Sound_Setting=2)?(HList:=["1:Hide","1:Hide","1:Hide","1:Hide","1:Show","1:Show","1:Hide"])
	:(Sound_Setting=3)?(HList:=["1:Hide","1:Hide","1:Hide","1:Hide","1:Show","1:Hide","1:Show"])
	for,k,v in HList
		GuiControl,% v,SG%A_Index%	
	return
Move_Window:
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		sleep 10
	WinGetPos,wx,wy,,,Hellbents StopWatch/Alarm TL
	Gui,1:Show,x%wx% y%wy%
	return
Minimize_Window:
	Gui,1:Minimize
	return
Move_Tab:
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		sleep,10
	WinGetPos,Tx,Ty,,,StopWatch Tab
	return
4Guicontextmenu:
	Gui,1:Show
	Gui,4:Destroy
	return
2Guicontextmenu:
	Gui,1:Minimize
	Gui,4:Destroy
	Gui,3:Destroy
	Gui,4:+AlwaysOnTop -Caption +Border +Owner1
	Gui,4:Color,0x72B4B1
	Gui,4:Font,cBlack s8 Bold Q5,Segoe UI	
	Gui,4:Add,Text,x0 y3 w40 h20 Center gMove_Tab,HBSW
	Gui,4:Show,x%Tx% y%Ty% w40 h20,StopWatch Tab
	return
Main_Clock:
	myHour:=A_Hour
	myHour>=13?myHour-=12:myHour<1?myHour+=12
	FormatTime, Time1,h , h tt
	StringRight,time2,time1,2
	GuiControl,1:,Main_Clock_Time,% MyHour " : " A_Min " : " A_Sec  "   " Time2 
	return
Flashing(){
	Gui,5:Destroy
	Gui,5:+AlwaysOnTop -Caption +Border +Owner1
	Gui,5:Color,Red
	Gui,5:Font,s12 Bold Q5,Segoe UI
	Gui,5:Add,Button,x120 y270 w60 h25 gTurn_Off_Alarm,Ok
	Gui,5:Show,w300 h300
}
Clock_Gui(){
	global
	Gui,1:+AlwaysOnTop -Caption 
	Gui,2:+AlwaysOnTop -Caption +Owner1 +LastFound
	WinSet,Transparent,1
	Gui,2:Color,Blue
	Gui,1:Color,Black,0x72B4B1
	Gui,1:Add,Edit,x-100 y0 w10 h10
	Gui,1:Add,Progress,x0 y0 w300 h65 BackgroundBlack c0x72B4B1,100
	Gui,1:Font,cBlack s12 underline Bold Q5 ,Nirmala UI
	Gui,1:Add,Text,x25 y0  r1 Backgroundtrans ,Hellbents StopWatch
	For k,v in ["x5 y15 w2 h5 Backgroundaa8800 vSG1","x+1 y11 w2 h9 Backgroundaaff00 vSG2","x+1 y7 w2 h13 Background00ff00 vSG3","x+1 y4 w2 h16 Background00ff00 vSG4"]
		Gui,1:Add,Progress,% v
	Gui,1:Font
	Gui,1:Font,cLime s9 Bold Q5 ,Nirmala UI
	Gui,1:Add,Progress,x5 y5 w15 h15 BackgroundBlack c555555 Hidden vSG5,100
	Gui,1:Add,Text,x5 y5 w15 r1 Center BackgroundTrans Hidden vSG6,M
	Gui,1:Font
	Gui,1:Font,cLime s12 Bold Q5 ,Nirmala UI
	Gui,1:Add,Text,x5 y0 w15 r1 Center BackgroundTrans Hidden vSG7,+
	Gui,1:Font
	Gui,1:Font,cYellow s9 Bold Q5 ,Nirmala UI
	For k,v in ["x200 y5 w15 h15 BackgroundBlack c555555","x220 y5 w15 h15 BackgroundBlack c555555","x240 y5 w15 h15 BackgroundBlack c555555","x260 y5 w15 h15 BackgroundBlack c555555","x280 y5 w15 h15 BackgroundBlack c555555"]
		Gui,1:Add,Progress,% v ,100
	Button_Text1 := ["C","A","S","-","X"]
	For k,v in ["x200 y5 w15 r1 Center BackgroundTrans","x220 y5 w15 r1 Center BackgroundTrans","x240 y5 w15 r1 Center BackgroundTrans","x260 y5 w15 r1 Center BackgroundTrans","x280 y5 w15 r1 Center BackgroundTrans"]
		Gui,1:Add,Text,% v ,% Button_Text1[A_Index]
	Gui,1:Font
	Gui,1:Font,cBlack s14  Bold Q5 ,Nirmala UI
	Gui,1:Add,Edit, x2 y25 w296 h20 Center -E0x200 BackgroundTrans vMain_Clock_Time ,% MyHour " : " A_Min " : " A_Sec  "   " Time2
	Gui,1:Add,Edit,x10 y25 w180 h20  BackgroundTrans -E0x200 Hidden vStop_Watch,000 : 00 : 00 : 000
	For,k,v in ["x192 y27 w22 h22 BackgroundBlack csilver Hidden vSW1","x229 y27 w22 h22 BackgroundBlack csilver Hidden vSW3","x266 y27 w22 h22 BackgroundBlack csilver Hidden vSW5"]
		Gui,1:Add,Progress,% v ,100
	NL1:= ["S","P","R"]	
	for,k,v in ["x192 y25 w22 r1 Center Backgroundtrans Hidden vSW2","x229 y25 w22 r1 Center Backgroundtrans Hidden vSW4","x266 y25 w22 r1 Center Backgroundtrans Hidden vSW6"]
		Gui,1:Add,Text,% v,% NL1[A_Index]
	Gui,1:Add,Progress,x10 y53 w280 h10 BackgroundBlack cred vAlarm_Progress range0-1000,
	for,k,v in ["x1 y0 w20 h23 Border gSounds","x25 y0 w170 h20 Border gMove_Window","x200 y5 w15 h15 Border gShow_Clock","x220 y5 w15 h15 Border gSet_Alarm","x240 y5 w15 h15 Border gShow_StopWatch","x260 y5 w15 h15 Border gMinimize_Window","x280 y5 w15 h15 Border gGuiClose","x192 y27 w22 h22 Border Hidden vSW7 gStart_StopWatch","x229 y27 w22 h22 Border Hidden vSW8 gPause_StopWatch","x266 y27 w22 h22 Border Hidden vSW9 gReset_StopWatch"]
		Gui,2:Add,Text,% v
	Gui,1:Show,x900 y50 w300 h65 ,Hellbents StopWatch/Alarm BL
	Gui,2:Show,x900 y50 w300 h65 ,Hellbents StopWatch/Alarm TL
}
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Simple Countdown Timer in Gui?

19 Dec 2017, 03:53

Try this, I modified it from https://autohotkey.com/board/topic/1815 ... ntry118827

Code: Select all

;On-screen display (OSD)

CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).

Gui +LastFound +AlwaysOnTop +Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.

Gui, Color, %CustomColor%

Gui, Font, s32  ; Set a large font size (32-point).

;~ Gui, Add, Text, vMyText cBlue, -00:00:00 ; XX & YY serve to auto-size the window.

Gui, Add, Text, w300 vMyTime cBlue, -00:00:00 ; XX & YY serve to auto-size the window.

WinSet, TransColor, %CustomColor% 150 ; Make all pixels of this color transparent and make the text itself translucent (150):


Inputbox, vCountdown, CountDown time, Please enter the time in Minutes ; inputbox to specify the amount of time to countdown

gosub, CountDownTime 

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

Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.

Gui, Show, x0 y80 NoActivate, Timer ; NoActivate avoids deactivating the currently active window.



Return  ; // End of Auto-Execute Section





CountDownTime:		; to add the countdown time to A_Now 
arrivo = 		; set arrivo to A_Now
arrivo += %vCountdown%, minutes	; add the user inputted countdown time
return

UpdateOSD:

mysec := arrivo                 

EnvSub, mysec, %A_Now%, seconds

;~ GuiControl,, MyText, %A_Hour%:%A_Min%:%A_Sec%
GuiControl,, MyTime, % FormatSeconds( MySec )

Return 


FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{

    time = 19000101  ; *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  
}


esc::
GuiClose:
Exitapp

TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Re: Simple Countdown Timer in Gui?

17 Jan 2018, 10:19

Hellbent wrote:not sure if this will be helpful, but it does do a few of the things you are looking to do.

Code: Select all

;Writtn By: Hellbent aka CivReborn
;Written for: CivReborn Youtube Channel- https://www.youtube.com/user/CivReborn
;Date Written: Nov 26th, 2017
;Paste: https://pastebin.com/HxgmZVXF
#SingleInstance,Force
global StopWatch_State:=0,Pauseit:=0,Sound_Setting:=1,Tx:=600,Ty:=100,myHour:=A_Hour,Alarm_Off:=0,colour_List:= ["Lime","Yellow","Red"],lnum:=1
FormatTime, Time1,h , h tt
StringRight,time2,time1,2
myHour>=13?myHour-=12:myHour<1?myHour+=12
Clock_Gui()
SetTimer,Main_Clock,1000
return
Turn_Off_Alarm:
	Alarm_Off:=1
	return
Watch_Alarm:
	New_Second:=(A_TickCount-Alarm_Tick)//1000
	if(New_Second>Last_Second){
		Last_Second:=New_Second
		GuiControl,1:,Alarm_Progress,% Last_Second
		update_edit3_1:=(Alarm_Seconds-Last_Second)//60,update_edit3_2:=(Alarm_Seconds-Last_Second)-(update_edit3_1*60),update_Edit3_1<10?update_edit3_1:="0" update_edit3_1,update_Edit3_2<10?update_edit3_2:="0" update_edit3_2
		GuiControl,3:,edit3,% update_edit3_1 " : " update_edit3_2
	}
	if(Last_Second>=Alarm_Seconds){
		if(Sound_Setting=1){
			SetTimer,Watch_Alarm,Off
			Gui,1:Show
			Gui,4:Destroy
			while(!GetKeyState("RButton"))
				SoundBeep,850,500
			GuiControl,1:,Alarm_Progress,0
		}else if(Sound_Setting=2){
				SetTimer,Watch_Alarm,Off
				Gui,1:Show
				Gui,4:Destroy
				Flashing()
				while(Alarm_Off=0){
					Gui,5:Color,% colour_List[lnum]
					lnum++
					(lnum=4)?(lnum:=1)
					sleep,500
				}
			GuiControl,1:,Alarm_Progress,0
			Gui,5:Destroy
		}else if(Sound_Setting=3){
			SetTimer,Watch_Alarm,Off
			Gui,1:Show
			Gui,4:Destroy
			Flashing()
			while(Alarm_Off=0&&!GetKeyState("RButton")){
				Gui,5:Color,% colour_List[lnum]
				lnum++
				(lnum=4)?(lnum:=1)
				SoundBeep,850,500
			}
			GuiControl,1:,Alarm_Progress,0
			Gui,5:Destroy
		}
	}
	return
Set_Alarm_Time:
	if(Time_Radio=1)
		Alarm_Seconds:=3600
	else if(Time_Radio=2)
		Alarm_Seconds:=(Min_Slide*60)+Sec_Slide
	GuiControl,1:+Range0-%Alarm_Seconds%,Alarm_Progress
	GuiControl,1:,Alarm_Progress,0
	Last_Second:=0,Alarm_Tick:=A_TickCount,Alarm_Off:=0
	SetTimer,Watch_Alarm,333
	Gui,3:Destroy
	return
Cancel:
	Gui,3:Destroy
	return
Submit_All:
	Gui,3:Submit,NoHide
	GuiControl,3:,edit1,% Min_Slide
	GuiControl,3:,edit2,% Sec_Slide
	if(Time_Radio=1)
		GuiControl,3:,edit3,60 : 00
	else
		GuiControl,3:,edit3,% Min_Slide " : " Sec_Slide
	return
Reset:
	Gui,3:Destroy
	SetTimer,Watch_Alarm,Off
	GuiControl,1:,Alarm_Progress,0
	return
set_Alarm:
	Gui,3:Destroy
	Gui,3:+AlwaysOnTop -Caption +Owner1 +Border
	Gui,3:Color,0x72B4B1
	Gui_Control_Types := ["Radio","Radio","Groupbox","Text","Slider","Edit","Groupbox","Text","Slider","Edit","Groupbox","Edit","Groupbox","Button","Button","Button"]
	Control_Text:= ["1 Hour","Set Amount",Fake_Value,"Mins:",Fake_Value,Fake_Value,Fake_Value,"Secs:",Fake_Value,Fake_Value,Fake_Value,"60 : 00",Fake_Value,"Set","Reset","Back"],Fake_Value:=""
	for k, v in ["x10 y10 Checked vTime_Radio gSubmit_All","x100 y10 gSubmit_All","x10 y30 w200 h60 Section","xs+10 ys+20 w30,Mins:","x+10 w100 Range0-59 AltSubmit vMin_Slide gSubmit_All","x+10 w30 Center ReadOnly -E0x200 vedit1","x10 y100 w200 h60 Section","xs+10 ys+20 w30","x+10 w100 Range0-59 AltSubmit vSec_Slide gSubmit_All","x+10 w30 Center ReadOnly -E0x200 vedit2","x10 y160 w200 h40 Section","xs+10 ys+13 w180 h20 ReadOnly Center -E0x200 vedit3","x10 y200 w200 h40 Section","xs+10 ys+13 w50 h20 gSet_Alarm_Time","x+15 ys+13 w50 h20 gReset","x+15 ys+13 w50 h20 gCancel"]
		Gui,3:Add,% Gui_Control_Types[A_Index],% v ,% Control_Text[A_Index]
	gosub,Submit_All
	Gui,3:Show,AutoSize ,Alarm Setup
	return
Show_StopWatch:
	GuiControl,1:Hide,Main_Clock_Time
	GuiControl,1:Show,Stop_Watch
	Loop 6
		GuiControl,1:Show,SW%A_Index%
	Loop 3
		GuiControl,2:Show,% "SW" A_Index+6
	return
Show_Clock:
	GuiControl,1:Hide,Stop_Watch
	Loop 6
		GuiControl,1:Hide,SW%A_Index%
	Loop 3
		GuiControl,2:Hide,% "SW" A_Index+6
	GuiControl,1:Show,Main_Clock_Time	
	return	
Start_StopWatch:
	if(StopWatch_State=0){
		StopWatch_State:=1,Pauseit:=0,Start_Tick:=A_TickCount
		SetTimer,StopWatch_Timer,10
	}
	return
Pause_StopWatch:
	if(StopWatch_State=1)
		Pauseit:=!Pauseit,Start_Tick:=A_TickCount-Start_Tick
	return
Reset_StopWatch:
	StopWatch_State:=0
	Pauseit:=0
	SetTimer,StopWatch_Timer,Off
	GuiControl,1:,Stop_Watch, 000 : 00 : 00 : 000
	return
StopWatch_Timer:
	Stop_Hour:=((A_TickCount-Start_Tick)//3600000) 
	Stop_Min:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000))//60000) 
	Stop_Sec:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000)-(Stop_Min*60000))//1000) 
	Stop_MS:=(((A_TickCount-Start_Tick)-(Stop_Hour*3600000)-(Stop_Min*60000)-(Stop_Sec*1000)))
	Stop_Hour<10?Stop_Hour:="00" Stop_Hour
	Stop_Min<10?Stop_Min:="0" Stop_Min
	Stop_Sec<10?Stop_Sec:="0" Stop_Sec
	Stop_MS<100?Stop_MS:="0" Stop_MS
	if(Pauseit=0)
	GuiControl,1:,Stop_Watch,% Stop_Hour " : " Stop_Min " : " Stop_Sec " : " Stop_Ms 
	return
GuiClose:
	ExitApp
Sounds:
	Sound_Setting++
	Sound_Setting>=4?Sound_Setting:=1
	(Sound_Setting=1)?(HList:=["1:Show","1:Show","1:Show","1:Show","1:Hide","1:Hide","1:Hide"])
	:(Sound_Setting=2)?(HList:=["1:Hide","1:Hide","1:Hide","1:Hide","1:Show","1:Show","1:Hide"])
	:(Sound_Setting=3)?(HList:=["1:Hide","1:Hide","1:Hide","1:Hide","1:Show","1:Hide","1:Show"])
	for,k,v in HList
		GuiControl,% v,SG%A_Index%	
	return
Move_Window:
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		sleep 10
	WinGetPos,wx,wy,,,Hellbents StopWatch/Alarm TL
	Gui,1:Show,x%wx% y%wy%
	return
Minimize_Window:
	Gui,1:Minimize
	return
Move_Tab:
	PostMessage,0xA1,2
	While(GetKeyState("LButton"))
		sleep,10
	WinGetPos,Tx,Ty,,,StopWatch Tab
	return
4Guicontextmenu:
	Gui,1:Show
	Gui,4:Destroy
	return
2Guicontextmenu:
	Gui,1:Minimize
	Gui,4:Destroy
	Gui,3:Destroy
	Gui,4:+AlwaysOnTop -Caption +Border +Owner1
	Gui,4:Color,0x72B4B1
	Gui,4:Font,cBlack s8 Bold Q5,Segoe UI	
	Gui,4:Add,Text,x0 y3 w40 h20 Center gMove_Tab,HBSW
	Gui,4:Show,x%Tx% y%Ty% w40 h20,StopWatch Tab
	return
Main_Clock:
	myHour:=A_Hour
	myHour>=13?myHour-=12:myHour<1?myHour+=12
	FormatTime, Time1,h , h tt
	StringRight,time2,time1,2
	GuiControl,1:,Main_Clock_Time,% MyHour " : " A_Min " : " A_Sec  "   " Time2 
	return
Flashing(){
	Gui,5:Destroy
	Gui,5:+AlwaysOnTop -Caption +Border +Owner1
	Gui,5:Color,Red
	Gui,5:Font,s12 Bold Q5,Segoe UI
	Gui,5:Add,Button,x120 y270 w60 h25 gTurn_Off_Alarm,Ok
	Gui,5:Show,w300 h300
}
Clock_Gui(){
	global
	Gui,1:+AlwaysOnTop -Caption 
	Gui,2:+AlwaysOnTop -Caption +Owner1 +LastFound
	WinSet,Transparent,1
	Gui,2:Color,Blue
	Gui,1:Color,Black,0x72B4B1
	Gui,1:Add,Edit,x-100 y0 w10 h10
	Gui,1:Add,Progress,x0 y0 w300 h65 BackgroundBlack c0x72B4B1,100
	Gui,1:Font,cBlack s12 underline Bold Q5 ,Nirmala UI
	Gui,1:Add,Text,x25 y0  r1 Backgroundtrans ,Hellbents StopWatch
	For k,v in ["x5 y15 w2 h5 Backgroundaa8800 vSG1","x+1 y11 w2 h9 Backgroundaaff00 vSG2","x+1 y7 w2 h13 Background00ff00 vSG3","x+1 y4 w2 h16 Background00ff00 vSG4"]
		Gui,1:Add,Progress,% v
	Gui,1:Font
	Gui,1:Font,cLime s9 Bold Q5 ,Nirmala UI
	Gui,1:Add,Progress,x5 y5 w15 h15 BackgroundBlack c555555 Hidden vSG5,100
	Gui,1:Add,Text,x5 y5 w15 r1 Center BackgroundTrans Hidden vSG6,M
	Gui,1:Font
	Gui,1:Font,cLime s12 Bold Q5 ,Nirmala UI
	Gui,1:Add,Text,x5 y0 w15 r1 Center BackgroundTrans Hidden vSG7,+
	Gui,1:Font
	Gui,1:Font,cYellow s9 Bold Q5 ,Nirmala UI
	For k,v in ["x200 y5 w15 h15 BackgroundBlack c555555","x220 y5 w15 h15 BackgroundBlack c555555","x240 y5 w15 h15 BackgroundBlack c555555","x260 y5 w15 h15 BackgroundBlack c555555","x280 y5 w15 h15 BackgroundBlack c555555"]
		Gui,1:Add,Progress,% v ,100
	Button_Text1 := ["C","A","S","-","X"]
	For k,v in ["x200 y5 w15 r1 Center BackgroundTrans","x220 y5 w15 r1 Center BackgroundTrans","x240 y5 w15 r1 Center BackgroundTrans","x260 y5 w15 r1 Center BackgroundTrans","x280 y5 w15 r1 Center BackgroundTrans"]
		Gui,1:Add,Text,% v ,% Button_Text1[A_Index]
	Gui,1:Font
	Gui,1:Font,cBlack s14  Bold Q5 ,Nirmala UI
	Gui,1:Add,Edit, x2 y25 w296 h20 Center -E0x200 BackgroundTrans vMain_Clock_Time ,% MyHour " : " A_Min " : " A_Sec  "   " Time2
	Gui,1:Add,Edit,x10 y25 w180 h20  BackgroundTrans -E0x200 Hidden vStop_Watch,000 : 00 : 00 : 000
	For,k,v in ["x192 y27 w22 h22 BackgroundBlack csilver Hidden vSW1","x229 y27 w22 h22 BackgroundBlack csilver Hidden vSW3","x266 y27 w22 h22 BackgroundBlack csilver Hidden vSW5"]
		Gui,1:Add,Progress,% v ,100
	NL1:= ["S","P","R"]	
	for,k,v in ["x192 y25 w22 r1 Center Backgroundtrans Hidden vSW2","x229 y25 w22 r1 Center Backgroundtrans Hidden vSW4","x266 y25 w22 r1 Center Backgroundtrans Hidden vSW6"]
		Gui,1:Add,Text,% v,% NL1[A_Index]
	Gui,1:Add,Progress,x10 y53 w280 h10 BackgroundBlack cred vAlarm_Progress range0-1000,
	for,k,v in ["x1 y0 w20 h23 Border gSounds","x25 y0 w170 h20 Border gMove_Window","x200 y5 w15 h15 Border gShow_Clock","x220 y5 w15 h15 Border gSet_Alarm","x240 y5 w15 h15 Border gShow_StopWatch","x260 y5 w15 h15 Border gMinimize_Window","x280 y5 w15 h15 Border gGuiClose","x192 y27 w22 h22 Border Hidden vSW7 gStart_StopWatch","x229 y27 w22 h22 Border Hidden vSW8 gPause_StopWatch","x266 y27 w22 h22 Border Hidden vSW9 gReset_StopWatch"]
		Gui,2:Add,Text,% v
	Gui,1:Show,x900 y50 w300 h65 ,Hellbents StopWatch/Alarm BL
	Gui,2:Show,x900 y50 w300 h65 ,Hellbents StopWatch/Alarm TL
}
That's nifty, and even handy, but it's not a countdown timer per say. Thank you though.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Simple Countdown Timer in Gui?

17 Jan 2018, 10:49

I've created a simple (countdown)timer function to shut down whatever application in time.
To display the outcome in a GUI (instead of a ToolTip) shouldn't be that tough to add. Good luck :)
https://autohotkey.com/boards/viewtopic ... 10&t=33332 (English comments)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, haomingchen1998, Peiya, rubeusmalfoy and 110 guests