Jump to content

Put GUI to sleep


Recommended Posts

Hi there I am using a GUI with the onevent mode:

#include <Date.au3>

Local $Starttime = IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set")

Local $Endtime = IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set")

; Timer related

$CurrentTime = _NowTime(4)

GUI Stuff

...

...

...

; GUI Events

While 1

Sleep(100)

; Check Software Run Time or not

Switch @WDAY

Case 1,2,3,4,5,6,7

If ($CurrentTime > $StartTime AND $CurrentTime < $EndTime) Then

;SplashTextOn("Software", "Within Time Period: Running.", -1, -1, -1, -1, 3, "", 24)

;Sleep(3000)

;SplashOff()

GUISetState(@SW_SHOW)

ElseIf ($CurrentTime < $StartTime AND $CurrentTime > $EndTime) Then

;MSGBOX(0,"Software in Pause Mode","From "&$StartTime&" to: "&$EndTime)

SplashTextOn("Software", "Sleeping...", -1, -1, -1, -1, 3, "", 24)

Sleep(3000)

SplashOff()

GUISetState(@SW_HIDE)

EndIf

EndSwitch

WEnd

Why is this not working? :

Link to comment
Share on other sites

You only check the current time once at the beginning of the script, the value isn't ever updated.

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

This should work, please test to see if this is what you need

Local $Starttime = "18:04:00" ; IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set")
Local $Endtime = "18:04:30" ; IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set")
$start = StringReplace($Starttime, ":", "")
$end = StringReplace($Endtime, ":", "")
$hidden = 0

$gui = GuiCreate("")
GuiSetState()

While 1
Sleep(100)
$cur = @HOUR & @MIN & @SEC ; Current Time
If $cur > $start AND $cur < $end Then
If $hidden = 1 Then
$hidden = 0
MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime)
GUISetState(@SW_SHOW)
EndIf
ElseIf $cur < $start OR $cur > $end Then
If $hidden = 0 Then
$hidden = 1
MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime)
GUISetState(@SW_HIDE)
EndIf
EndIf
WEnd
BTW you'd better put this checking stuff in a AdlibRegister

Edited by mikell
Link to comment
Share on other sites

Hmm

I added the seconds to the times (current, start & end) in the code because this makes it much easier to test, so be careful with the time format

Did you change something in the code ?

The code above (and below) first shows the gui, then hides it if current time is out of the time range, shows it when it comes into the range, and hides it again after the endtime etc

Local $Starttime = "19:34:00" ; IniRead("settings.ini", "SectionstartTime", "Starttime", "Start Time Note Set")
Local $Endtime = "19:34:30" ; IniRead("settings.ini", "SectionendTime", "Endtime", "End Time Note Set")
$start = StringReplace($Starttime, ":", "")
$end = StringReplace($Endtime, ":", "")

$hidden = 0 ; gui is visible

$gui = GuiCreate("")
GuiSetState()

While 1
Sleep(100)
$cur = @HOUR & @MIN & @SEC ; get current time ( format hhmmss )
If $cur > $start AND $cur < $end Then ; if in the range
If $hidden = 1 Then ; if gui is hidden
$hidden = 0 ; show it
MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime)
GUISetState(@SW_SHOW)
EndIf
ElseIf $cur < $start OR $cur > $end Then ; if out of the range
If $hidden = 0 Then ; if gui is visible
$hidden = 1 ; hide it
MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime)
GUISetState(@SW_HIDE)
EndIf
EndIf
WEnd
Edited by mikell
Link to comment
Share on other sites

Try it. It doesnt work on starting the script and it also doesnt "switcht" e.g. from hide to show WHILE running the script :-(

I understand your code and it SHOULD work but it doesnt :-(

Also:

$start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", "")

Shoudnt this be:

$start = StringReplace($Starttime, ":", "") $end = StringReplace($Endtime, ":", ":", "")

Edited by R4z0r
Link to comment
Share on other sites

No, StringReplace() replaces all occurences of the searchstring (default)

Put some ConsoleWrite inside the code to note it

Otherwise, tricky... I really don't understand why it doesn't work for you. Did you modify something in the code I wrote ?

Edit

StringReplace("19:34:00", ":", "") => 193400

What did you write for $Starttime ?

Edited by mikell
Link to comment
Share on other sites

I didnt modify anything. Now I changed to code to:

I removed the seconds and did this:

While 1

$cur = @HOUR & @MIN ; get current time ( format hhmm )

MsgBox(0,"Time?",$cur,30)

MsgBox(0,"Time Check",$start&" "&$end,30)

; main/idle GUI switch statement

Switch GUIGetMsg()

; Case $GUI_EVENT_CLOSE

; GUIDelete()

; Exit

Case $cur > $start AND $cur < $end

If $hidden = 1 Then $hidden = 0

MSGBOX(0,"Running","From "&$StartTime&" to: "&$EndTime)

GUISetState(@SW_SHOW)

Case $cur < $start OR $cur > $end

If $hidden = 0 Then $hidden = 1

MSGBOX(0,"Pause","From "&$EndTime&" to: "&$StartTime)

GUISetState(@SW_HIDE)

EndSwitch

Sleep(10)

WEnd

This

MsgBox(0,"Time Check",$start&" "&$end,30)

Returns "85 86"

So where is the mistake???

Link to comment
Share on other sites

No, StringReplace() replaces all occurences of the searchstring (default)

Put some ConsoleWrite inside the code to note it

Otherwise, tricky... I really don't understand why it doesn't work for you. Did you modify something in the code I wrote ?

Edit

StringReplace("19:34:00", ":", "") => 193400

What did you write for $Starttime ?

e.g. Starttime = "20:00:30"

Link to comment
Share on other sites

And I have this:

;TEST

$StartTime = IniRead("settings.ini", "SectionstartTime", "StartTime", "Start Time Note Set")

$EndTime = IniRead("settings.ini", "SectionendTime", "EndTime", "End Time Note Set")

;$start = StringReplace($StartTime, ":", "")

$start = $StartTime

;$end = StringReplace($EndTime, ":", "")

$end = $EndTime

$hidden = 0

;TEST

I tried without iniread like $StartTime = "20:15:00"

Link to comment
Share on other sites

OMG!!!!

This is the problem?

Global $Start = GUICtrlCreateInput($StartTime, 144, 152, 97, 33)

GUICtrlSetFont(-1, 16, 400, 0, "Century Schoolbook")

GUICtrlSetOnEvent(-1, "StartChange")

Global $End = GUICtrlCreateInput($EndTime, 248, 152, 97, 33)

GUICtrlSetFont(-1, 16, 400, 0, "Century Schoolbook")

GUICtrlSetOnEvent(-1, "EndChange")

Link to comment
Share on other sites

I didnt modify anything.

Are you joking ?!? the code you posted is VERY different from mine, and contains a lot of mistakes

Switch GUIGetMsg() ... Case $cur => wrong

If $hidden = 1 Then... => you completely changed the content of the conditions

First try to run my code WITH NO CHANGES except the time values in the 2 top lines

Then ask and/or look at the helpfile before changing the statements :ermm:

Edited by mikell
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...