Jump to content

Have GUI pop-up every hour after clicking "hide" button


Recommended Posts

This GUI has a countdown timer from the specified date in the code in days, hours, minutes and seconds.  When the script is ran, it will display the countdown time and I also have a "hide" button that will hide the GUI.  I would like this GUI to pop up every hour from the time the "hide" button is clicked.

The problem is, since that will need to be in a loop (I think), I not sure what to do so it doesn't impact the time being updated while that loop is running.

 

#NoTrayIcon


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


Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode


Global $SS_CENTER, $_Minutes, $_Seconds


$sStartDate = @YEAR & "/" & @MON & "/" & @MDAY
$sEndDate = "2019/10/01"
$test = _DateDiff ("D", $sStartDate, $sEndDate )


$GetMinutesLeft = 1440 * $test
$GetSecondsLeft = 60 * $GetMinutesLeft
$GetMilisecondsLeft = 1000 * $GetSecondsLeft
$CountdownTime = $GetMilisecondsLeft
$PCSpeakerBeepNotification = 60


$_GuiCountDown = GUICreate ( "Title Bar", 1020, 220, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST  )
GUICtrlCreateLabel("Total time remaining:", 25, 30, 520,26)
GUICtrlSetFont ( -1, 9, 800 )
GUISetBkColor ( 0xFFFFFF )
$TimeLabel = GUICtrlCreateLabel ( "", 205, 20, 780, 150, $SS_CENTER )
GUICtrlSetFont ( -1, 25, 800 )
GUICtrlSetColor(-1,0xff0000)
WinSetOnTop ( $_GuiCountDown, "", 1 )
$TimeTicks = TimerInit ( )
$Hide = GUICtrlCreateButton("Hide", 20,80,100,35)
GUICtrlSetOnEvent($Hide, "Hide")


While 1
  _Check ( )
  Sleep(200)
  GUISetState(@SW_SHOW)
WEnd


Func Hide()
  GUISetState(@SW_HIDE)
EndFunc


Func _Check ( )

$time = "2019/10/01 12:00:00"
$td = _DateDiff('s', _NowCalc(), $time)

      $late = ""; dummy neg no
      If $td < 0 Then $late = "-"; dummy neg yes
      If $td < 0 Then $td = -$td; convert neg $td to pos for math

      $d = 0; Days with remainder math
      If $td > 86400 Then
          $dm = $td
          Do
              $dm = $dm - 86400
              $d = $d + 1
          Until $dm < 86400
      EndIf

      $h = 0; Hours with remainder math
      If $td - ($d * 86400) > 3600 Then
          $hm = $td - ($d * 86400)
          Do
              $hm = $hm - 3600
              $h = $h + 1
          Until $hm < 3600
      EndIf

      $m = 0; Miutes with remainder math
      If $td - ($d * 86400) - ($h * 3600) > 60 Then
          $mm = $td - ($d * 86400) - ($h * 3600)
          Do
              $mm = $mm - 60
              $m = $m + 1
          Until $mm < 60
      EndIf

      $s = $td - ($d * 86400) - ($h * 3600) - ($m * 60); Seconds

      $db = ""; non zero for 2 digit numbers
      $hb = ""
      $mb = ""
      $sb = ""

      If $d < 10 Then $db = 0; zero for 1 digit number
      If $h < 10 Then $hb = 0
      If $m < 10 Then $mb = 0
      If $s < 10 Then $sb = 0
            GUICtrlSetData ( $TimeLabel, StringFormat ( $late & $db & $d & " days, " & $hb & $h & " hours, "  & $mb & $m & " minutes and " & $sb & $s & " seconds", 10, 10) )
EndFunc ;==> _Check ( )

 

Edited by TheCrimsonCrusader
Code updated.
Link to comment
Share on other sites

Use AdLibRegister using your _Check function as the parameter, and just have it automatically check it every few seconds or less.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks.  I'm not understanding something, I placed the AdlibRegister("MyAdLibFunc",250) at the beginning of the _Check function to then call the "MyAdLibFunc" (updated code in this response) but that didn't process anything in that function as when I click on the hide button, the GUI doesn't come back after the 10 second sleep in the "MyAdLibFunc"

Sorry, I haven't messed with the AdLibRegistery before.

 

#NoTrayIcon


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


Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode


Global $SS_CENTER, $_Minutes, $_Seconds


$sStartDate = @YEAR & "/" & @MON & "/" & @MDAY
$sEndDate = "2019/10/01"
$test = _DateDiff ("D", $sStartDate, $sEndDate )


$GetMinutesLeft = 1440 * $test
$GetSecondsLeft = 60 * $GetMinutesLeft
$GetMilisecondsLeft = 1000 * $GetSecondsLeft
$CountdownTime = $GetMilisecondsLeft
$PCSpeakerBeepNotification = 60


$_GuiCountDown = GUICreate ( "Title Bar", 1020, 220, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST  )
GUICtrlCreateLabel("Total time remaining:", 25, 30, 520,26)
GUICtrlSetFont ( -1, 9, 800 )
GUISetBkColor ( 0xFFFFFF )
$TimeLabel = GUICtrlCreateLabel ( "", 205, 20, 780, 150, $SS_CENTER )
GUICtrlSetFont ( -1, 25, 800 )
GUICtrlSetColor(-1,0xff0000)
WinSetOnTop ( $_GuiCountDown, "", 1 )
$TimeTicks = TimerInit ( )
$Hide = GUICtrlCreateButton("Hide", 20,80,100,35)
GUICtrlSetOnEvent($Hide, "Hide")


GUISetState(@SW_SHOW)


While 1
  _Check ( )
  Sleep(100)
WEnd


Func Hide()
  GUISetState(@SW_HIDE)
EndFunc


Func _Check ( )

AdlibRegister("MyAdLibFunc",250)


$time = "2019/10/01 12:00:00"
$td = _DateDiff('s', _NowCalc(), $time)

      $late = ""; dummy neg no
      If $td < 0 Then $late = "-"; dummy neg yes
      If $td < 0 Then $td = -$td; convert neg $td to pos for math

      $d = 0; Days with remainder math
      If $td > 86400 Then
          $dm = $td
          Do
              $dm = $dm - 86400
              $d = $d + 1
          Until $dm < 86400
      EndIf

      $h = 0; Hours with remainder math
      If $td - ($d * 86400) > 3600 Then
          $hm = $td - ($d * 86400)
          Do
              $hm = $hm - 3600
              $h = $h + 1
          Until $hm < 3600
      EndIf

      $m = 0; Miutes with remainder math
      If $td - ($d * 86400) - ($h * 3600) > 60 Then
          $mm = $td - ($d * 86400) - ($h * 3600)
          Do
              $mm = $mm - 60
              $m = $m + 1
          Until $mm < 60
      EndIf

      $s = $td - ($d * 86400) - ($h * 3600) - ($m * 60); Seconds

      $db = ""; non zero for 2 digit numbers
      $hb = ""
      $mb = ""
      $sb = ""

      If $d < 10 Then $db = 0; zero for 1 digit number
      If $h < 10 Then $hb = 0
      If $m < 10 Then $mb = 0
      If $s < 10 Then $sb = 0
            GUICtrlSetData ( $TimeLabel, StringFormat ( $late & $db & $d & " days, " & $hb & $h & " hours, "  & $mb & $m & " minutes and " & $sb & $s & " seconds", 10, 10) )
EndFunc ;==> _Check ( )


Func MyAdLibFunc()
    Sleep(10000)
    GUISetState(@SW_SHOW)
EndFunc   ;==>MyAdLibFunc

 

Link to comment
Share on other sites

First, you have the AdLib call in the wrong place, you need to put it at the top of your script outside the function you're trying to register with it.

Second, why are you still running the Check function inside the While loop? The Adlib will do periodic runs of the function so that's not needed. 

How the function operates is up to your code, not using Adlibregister, that just calls the Check function every 10ms (not seconds).

Next, read the help file and run some of the examples to see how this function works.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

21 minutes ago, BrewManNH said:

First, you have the AdLib call in the wrong place, you need to put it at the top of your script outside the function you're trying to register with it.

Second, why are you still running the Check function inside the While loop? The Adlib will do periodic runs of the function so that's not needed. 

How the function operates is up to your code, not using Adlibregister, that just calls the Check function every 10ms (not seconds).

Next, read the help file and run some of the examples to see how this function works.

 

I had AdLib outside of the function previously, but I still run into the problem where if I have a sleep statement from the time I click on the "Hide" button, that has a direct impact on the countdown timer in terms of it pausing until that sleep statement ends.

So if I have an AdLibRegister for the _Check function and then another AdLibRegister for running the GUISetState(@SW_SHOW) after a sleep period after the hide button is clicked on, the countdown timer pauses until that sleep period has concluded and I need to keep those segregated.

 

#NoTrayIcon


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


Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode


Global $SS_CENTER, $_Minutes, $_Seconds


AdlibRegister("_Check",250)


$sStartDate = @YEAR & "/" & @MON & "/" & @MDAY
$sEndDate = "2019/10/01"
$test = _DateDiff ("D", $sStartDate, $sEndDate )


$GetMinutesLeft = 1440 * $test
$GetSecondsLeft = 60 * $GetMinutesLeft
$GetMilisecondsLeft = 1000 * $GetSecondsLeft
$CountdownTime = $GetMilisecondsLeft
$PCSpeakerBeepNotification = 60


$_GuiCountDown = GUICreate ( "Title Bar", 1020, 220, @DesktopWidth/2 -250, @DesktopHeight/2 -100, $WS_EX_TOPMOST  )
GUICtrlCreateLabel("Total time remaining:", 25, 30, 520,26)
GUICtrlSetFont ( -1, 9, 800 )
GUISetBkColor ( 0xFFFFFF )
$TimeLabel = GUICtrlCreateLabel ( "", 205, 20, 780, 150, $SS_CENTER )
GUICtrlSetFont ( -1, 25, 800 )
GUICtrlSetColor(-1,0xff0000)
WinSetOnTop ( $_GuiCountDown, "", 1 )
$TimeTicks = TimerInit ( )
$Hide = GUICtrlCreateButton("Hide", 20,80,100,35)
GUICtrlSetOnEvent($Hide, "Hide")


GUISetState(@SW_SHOW)


While 1
  Sleep(100)
WEnd


Func Hide()
  GUISetState(@SW_HIDE)
EndFunc


Func _Check ( )

$time = "2019/10/01 12:00:00"
$td = _DateDiff('s', _NowCalc(), $time)

      $late = ""; dummy neg no
      If $td < 0 Then $late = "-"; dummy neg yes
      If $td < 0 Then $td = -$td; convert neg $td to pos for math

      $d = 0; Days with remainder math
      If $td > 86400 Then
          $dm = $td
          Do
              $dm = $dm - 86400
              $d = $d + 1
          Until $dm < 86400
      EndIf

      $h = 0; Hours with remainder math
      If $td - ($d * 86400) > 3600 Then
          $hm = $td - ($d * 86400)
          Do
              $hm = $hm - 3600
              $h = $h + 1
          Until $hm < 3600
      EndIf

      $m = 0; Miutes with remainder math
      If $td - ($d * 86400) - ($h * 3600) > 60 Then
          $mm = $td - ($d * 86400) - ($h * 3600)
          Do
              $mm = $mm - 60
              $m = $m + 1
          Until $mm < 60
      EndIf

      $s = $td - ($d * 86400) - ($h * 3600) - ($m * 60); Seconds

      $db = ""; non zero for 2 digit numbers
      $hb = ""
      $mb = ""
      $sb = ""

      If $d < 10 Then $db = 0; zero for 1 digit number
      If $h < 10 Then $hb = 0
      If $m < 10 Then $mb = 0
      If $s < 10 Then $sb = 0
            GUICtrlSetData ( $TimeLabel, StringFormat ( $late & $db & $d & " days, " & $hb & $h & " hours, "  & $mb & $m & " minutes and " & $sb & $s & " seconds", 10, 10) )
EndFunc ;==> _Check ( )

 

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