<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=8176&amp;type=atom" />
	<updated>2013-04-14T21:40:44Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=8176</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71368#p71368" />
			<content type="html"><![CDATA[<p>Осенило быдлокодера <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Вроде как учтены переходы между сутками, годами. + точный повторный таймер на следующие сутки, учитывая если блокировка произошла при старте (в период <em>MaxInterval</em>). <br /></p><div class="codebox"><pre><code>

#SingleInstance force  
BlockTime = 15:47
MaxInterval = 5
 
Gui, Add, CheckBox, vCheckTimeSynh gCheckBox, % &quot;&quot;
Gui, Add, Button, x+1 yp vTimeSynh w110, TimeSynh
Gui, Add, CheckBox, xm vCheckUpdate gCheckBox, % &quot;&quot;
Gui, Add, Button, x+1 yp w110 vUpdate, Update 
Gui, Show, , Update &amp; TimeSynh

UpdTimerInterval:
    Timer := DifferenceTime(BlockTime)
    If (Timer &lt; 86400000 - (MaxInterval * 60000))
        SetTimer, TimeBlockButton, % Timer
    Else
        Gosub, TimeBlockButton 
    Return 

TimeBlockButton:   
    GuiControl, , CheckUpdate, 1 
    GuiControl, , CheckTimeSynh, 1 
    GuiControl, Disable, Update 
    GuiControl, Disable, TimeSynh 
UpdTimer:
    SetTimer, TimeBlockButton, % DifferenceTime(BlockTime)
    Return
    
DifferenceTime(Time)  {   
    Time := Time2 := A_YYYY A_MM A_DD RegExReplace(Time, &quot;:&quot;) 00  
    EnvSub, Time, A_Now, Second 
    Time := (Time * 1000) - A_MSec
    If Time &gt;= 0
        Return Time
    Time2 += 1, days
    EnvSub, Time2, A_Now, Second
    Return (Time2 * 1000) - A_MSec
}
    
CheckBox:
    GuiControlGet, %A_GuiControl%   
    GuiControl, % %A_GuiControl% ? &quot;Disable&quot; : &quot;Enable&quot;, % SubStr(A_GuiControl, 6)
    Return 

</code></pre></div><p><em>MaxInterval</em> - Кол-во минут, на которое текущее время может быть больше чем <em>BlockTime</em>, и всё равно блокировать при старте скрипта. <em>BlockTime</em> задаётся в четырёх значном формате, можно без двоеточия.<br />Функция <em>DifferenceTime</em> возвращает разницу текущего и указанного времени в миллисекундах. То есть если указано 01:00, а текущее время 02:00, то вернётся 23 часа в миллисекундах.<br />Использование команды &quot;Pause&quot; в данном случае не есть - ГУД. Хотя после паузы можно запускать метку &quot;UpdTimerInterval&quot; для обновления таймера с учётом <em>MaxInterval</em>, или &quot;UpdTimer&quot; без его учёта.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-14T21:40:44Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71368#p71368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71319#p71319" />
			<content type="html"><![CDATA[<p>В принципе можно сделать ещё одно время UNBlock, которое будет снимать блокировку. В моём случае программа имеет актуальность с 23 часов до 5 утра блок нужен на время до 9 утра, как раз заканчивается моя смена <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[unKn0wn]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27432</uri>
			</author>
			<updated>2013-04-12T11:50:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71319#p71319</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71160#p71160" />
			<content type="html"><![CDATA[<p>Озадачился вопросом. Получилось:<br /></p><div class="codebox"><pre><code>

BTHour := 20 , BTMin := 1 , MaxInterval := 5 , CurTime := A_Hour A_Min , BlockTime := BTHour BTMin , DMin := 60000
 
Gui, Add, CheckBox, vCheckUpdate Section gCheckUpdate
Gui, Add, Button, x+1 yp vUpdate, Update
Gui, Add, CheckBox, xs y+10 vCheckTimeSynh gCheckTimeSynh
Gui, Add, Button, x+1 yp vTimeSynh, TimeSynh
Gui, Show, , Update &amp; TimeSynh

If (CurTime &gt;= BlockTime &amp;&amp; CurTime &lt;= BlockTime + MaxInterval) 
    Gosub, TimeBlockButton  
Else If (CurTime &gt; BlockTime)  
    SetTimer, TimeBlockButton, %  ((23 - (A_Hour - BTHour)) * (DMin * 60)) + (60 - (Abs(BTMin - A_Min)) * DMin) - (A_Sec *1000)  
Else 
    SetTimer, TimeBlockButton, %  ((BTHour - A_Hour - 1) * (DMin * 60)) + ((60 - (A_Min-BTMin)) * DMin) - (A_Sec *1000)  
Return

TimeBlockButton:     
    SetTimer, TimeBlockButton, 86400000      ; Сутки 
    GuiControl, , CheckUpdate, 1 
    GuiControl, , CheckTimeSynh, 1 
    GuiControl, Disable, Update 
    GuiControl, Disable, TimeSynh 
    Return
    
CheckUpdate:
    GuiControlGet, CheckUpdate  
    GuiControl, % CheckUpdate ? &quot;Disable&quot; : &quot;Enable&quot;, Update 
    Return 
    
CheckTimeSynh:
    GuiControlGet, CheckTimeSynh
    GuiControl, % CheckTimeSynh ? &quot;Disable&quot; : &quot;Enable&quot;, TimeSynh
    Return

</code></pre></div><p><em>BTHour</em> - Час отключения<br /><em>BTMin</em> - Минута отключения<br /><em>MaxInterval</em> - Кол-во минут на которое время может быть больше, и всё равно блокировать</p><p>Проблемы: <br />Как учесть переходы с 59 на 00 в минутах при сравнении, и незабыть про MaxInterval<br />Как запускать таймер повторно, чтоб он срабатывал через сутки ровно в назначенное время.<br />Как вообще это проще сделать?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-07T16:27:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71160#p71160</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70811#p70811" />
			<content type="html"><![CDATA[<p>Вы правы. Наверное лучшим решением будет ставить галочки при запуске, а блокировку по времени использовать как страховку после использовании кнопки.</p>]]></content>
			<author>
				<name><![CDATA[unKn0wn]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27432</uri>
			</author>
			<updated>2013-03-26T16:32:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70811#p70811</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70757#p70757" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Вот ещё одно, если программу запустить после &quot;будильника&quot; то есть позже чем те-же 01:28 -на пример в 01:30 то не будет проверки на время при запуске и флажок не буде стоять?</p></blockquote></div><p>Тут вы уже должны полностью описать алгоритм. Задача была:</p><div class="quotebox"><blockquote><p>На пример в 02:00 ставится флажок</p></blockquote></div><p>А если повашему &quot;если программу запустить после &quot;будильника&quot; то флажок надо ставить всегда при страте. Ведь непонятно насколько больше текущее время должно быть больше от заданного для блокировки.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-03-24T23:41:49Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70757#p70757</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70756#p70756" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>На пример ставлю 01:28 и смотрю по сис времени, и уже только в 01:28:30 реагирует.</p></blockquote></div><br /><div class="codebox"><pre><code>SetTimer, Block, 50000</code></pre></div><p>Прверка каждые 50 секунд. Поставьте 1000 чтоб каждыю секунду проверялось.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-03-24T23:36:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70756#p70756</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70755#p70755" />
			<content type="html"><![CDATA[<p>Сглупил по невнимательности. С чекбоксами всё хорошо, могу в ручную галочками делать неактивными, напутал во время адаптации под себя <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />А вот с таймингамм -здесь даже не знаю, пробовал в вашем варианте и своём, всегда от 15-30 секунд разница, время я сверю с системным. На пример ставлю 01:28 и смотрю по сис времени, и уже только в 01:28:30 реагирует. Но это совсем не важно, это время не сыграет не какой роли.<br />Вот ещё одно, если программу запустить после &quot;будильника&quot; то есть позже чем те-же 01:28 -на пример в 01:30 то не будет проверки на время при запуске и флажок не буде стоять?</p>]]></content>
			<author>
				<name><![CDATA[unKn0wn]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27432</uri>
			</author>
			<updated>2013-03-24T23:29:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70755#p70755</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70752#p70752" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Только странно, в ручную если ставить галочку, то не дисэйблится боттон и немного таймер тормозит,</p></blockquote></div><p>Поподробнее.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-03-24T23:07:20Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70752#p70752</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70749#p70749" />
			<content type="html"><![CDATA[<p>Вот спасибо. Адаптировал под свой код, всё отлично. Только странно, в ручную если ставить галочку, то не дисэйблится боттон и немного таймер тормозит, сек на 30, но а в общем всё как нужно, вы даже учли то, что я не написал, сделали отдельные тайминги, вспомнил про это, уже когда ушел из дома <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br /><strong>2ypppu </strong> Английский я не очень хорошо знаю, тем более если читать подобное, да и пишу свои недо-когда по примерам и только, не так много знаний чтобы правильно понимать из описания даже русского.</p>]]></content>
			<author>
				<name><![CDATA[unKn0wn]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27432</uri>
			</author>
			<updated>2013-03-24T21:19:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70749#p70749</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70747#p70747" />
			<content type="html"><![CDATA[<p>Новичкам без примеров, тяжело.<br /></p><div class="codebox"><pre><code>

BlockTimeUpdate = 21:26
BlockTimeTimeSynh = 21:26

Gui, Add, Button, x82 y10 w100 h30 gUpdate vUpdate, Update
Gui, Add, CheckBox, x52 y10 w20 h20 vCheckUpdate gCheckUpdate
Gui, Add, Button, x82 y60 w100 h30 gTimeSynh vTimeSynh, TimeSynh
Gui, Add, CheckBox, x52 y60 w20 h20 vCheckTimeSynh gCheckTimeSynh
Gui, Show, x134 y81 h175 w223, New GUI Window  
SetTimer, Block, 50000 
Return
    
Block:
    If BlockTimeUpdate = %A_Hour%:%A_Min%
    {
        GuiControl,, CheckUpdate, 1
        Gosub, CheckUpdate
    }    
    If BlockTimeTimeSynh = %A_Hour%:%A_Min%
    {
        GuiControl,, CheckTimeSynh, 1 
        Gosub, CheckTimeSynh
    }
    Return

CheckUpdate:
    GuiControlGet, CheckUpdate 
    GuiControl, % CheckUpdate ? &quot;Disable&quot; : &quot;Enable&quot;, Update
    Return
    
CheckTimeSynh:
    GuiControlGet, CheckTimeSynh
    GuiControl, % CheckTimeSynh ? &quot;Disable&quot; : &quot;Enable&quot;, TimeSynh
    Return
    
Update: 
    MsgBox  D:\1\update.bat 
    Return

TimeSynh: 
    MsgBox  D:\1\timesynh.bat 
    Return   

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-03-24T17:29:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70747#p70747</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70746#p70746" />
			<content type="html"><![CDATA[<p>Почитайте <a href="http://forum.script-coding.com/viewtopic.php?id=8162">соседнюю тему</a>, там есть пример использования команды <em><strong>GUIControl,</strong> Disable</em>. В русскоязычной документации эта команда не расписана, но можно почитать на официальном сайте.<br />А ещё можно сделать перевод документации по этой команде (и увековечить своё имя в <a href="http://forum.script-coding.com/viewtopic.php?id=316">проекте перевода</a>).</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2013-03-24T17:04:43Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70746#p70746</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: GUI. Блокировка botton посредством флажка из checkbox'a]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70742#p70742" />
			<content type="html"><![CDATA[<p>На работе, в определённое время нужно запускать батники, и иногда дело происходит ночью, и спросонья можно 2 раза выполнить одно и тоже -что приведёт к двойному выполнению батника. Потому было бы здорово, чтобы чекбокс блокировал нажатие кнопки.<br />Хотелось, чтобы чекбокс ставил флажок на против кнопки в определённое время -тем самым блокировал кнопку(делал неактивной). На пример в 02:00 ставится флажок, и кнопка делается неактивной, но если вручную снять галочку чекбокса то кнопка становится активной.<br />Прошу помощи разобраться, здесь что-то совсем не могу понять без примера как такое сделать.</p><div class="codebox"><pre><code>
Gui, Add, Button, x82 y10 w100 h30 gUpdate, Button 1
Gui, Add, CheckBox, x52 y10 w20 h20 , 12

Gui, Add, Button, x82 y60 w100 h30 gTimeSynh, Button 2
Gui, Add, CheckBox, x52 y60 w20 h20 , 22

Gui, Show, x134 y81 h175 w223, New GUI Window
Return

Update:
 {
    Run D:\1\update.bat
 }
Return

TimeSynh:
 {
    Run D:\1\timesynh.bat
 }
Return

GuiClose:
ExitApp
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[unKn0wn]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27432</uri>
			</author>
			<updated>2013-03-24T16:27:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70742#p70742</id>
		</entry>
</feed>
