<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Button с картинкой (функция)]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12574&amp;type=atom" />
	<updated>2017-04-02T05:50:31Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=12574</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114504#p114504" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>stealzy пишет:</cite><blockquote><p>первая кнопка нажимается и действует, вторая после нажатия исчезает.</p></blockquote></div><p>Значит все работает как задумано (на исчезающей кнопке даже иконка удаления стоит для ясности, а вы потрудились 70кБ скачать).<br />Статическое количество контролов на форме - лишь частный случай, который не должен затруднять применение этого кода в других проектах, в которых количество контролов изменяется в процессе работы.</p><div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>mozers, я тоже не понимаю, чего вы хотите добиться.</p></blockquote></div><p>Цель - создать максимально простую и максимально полноценную функцию, которую потом без &quot;допиливания&quot; можно будет использовать где угодно.</p><p><strong>teadrinker</strong><br />И опять - интересный и наглядный код, который можно использовать в самых разнообразных проектах.</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2017-04-02T05:50:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114504#p114504</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114493#p114493" />
			<content type="html"><![CDATA[<p>В принципе не очень правильно создавать контрол &quot;динамически&quot;. Лучше заранее создать их скрытыми и показывать/скрывать, когда нужно.<br /></p><div class="codebox"><pre><code>IcoDll := &quot;Shell32.dll&quot;

handles := []
while (i := A_Index) &lt; 3
   Loop 3
      handles.Push( AddPicButton(10 + (A_Index - 1)*52, 40, 32, IcoDll, 22 + (i - 1)*3 + A_Index, Func(&quot;Action&quot;)) )

Gui, Add, Radio, vRadio1 x20 y10 Checked, Set1
Gui, Add, Radio, vRadio2 x+30 yp, Set2
toggle := Func(&quot;ChangeSet&quot;).Bind(handles, &quot;&quot;, 1)
Loop 2
   GuiControl, +g, Radio%A_Index%, % toggle

ChangeSet(handles, 1)
Gui, Show, w166 h90
Return

AddPicButton(x, y, size, IcoDll, n, action, GuiID := 1)  {
   static WS_EX_CLIENTEDGE := 0x200, WS_EX_DLGMODALFRAME := 0x1
   
   Gui, %GuiID%: Add, Pic, x%x% y%y% w%size% h-1 hwndhButtonDown +E%WS_EX_CLIENTEDGE% Icon%n% hidden, % IcoDll
   Gui, %GuiID%: Add, Pic, x%x% y%y% w%size% h-1 hwndhButtonUp +E%WS_EX_DLGMODALFRAME% Icon%n% hidden, % IcoDll
   OnClick := Func(&quot;OnClick&quot;).Bind(hButtonUp, hButtonDown, action, GuiID)
   GuiControl, +g, % hButtonUp, % OnClick
   Return hButtonUp
}

OnClick(hUp, hDown, action, GuiID)  {
   GuiControl, %GuiID%: Hide, % hUp
   GuiControl, %GuiID%: Show, % hDown
   KeyWait, LButton
   GuiControl, %GuiID%: Hide, % hDown
   GuiControl, %GuiID%: Show, % hUp
   MouseGetPos,,,, ControlID, 2
   ( ControlID = hUp &amp;&amp; action.Call() )
}
   
Action()  {
   MouseGetPos,,,, Control
   MsgBox, % &quot;Кнопка &quot; . RegExReplace(Control, &quot;.*?(\d+)&quot;, &quot;$1&quot;)//2
}

ChangeSet(handles, set, GuiID := 1)  {
   ( !set &amp;&amp; set := SubStr(A_GuiControl, 0) )
   for k, v in handles
      GuiControl, % GuiID . &quot;:&quot; . ( (set = 2) ^ (k &lt; 4) ? &quot;Show&quot; : &quot;Hide&quot; ), % v
}

GuiClose()  {
   ExitApp
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-04-01T16:53:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114493#p114493</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114485#p114485" />
			<content type="html"><![CDATA[<p><strong>mozers</strong>, я тоже не понимаю, чего вы хотите добиться.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-04-01T12:29:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114485#p114485</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114480#p114480" />
			<content type="html"><![CDATA[<p>У меня независимо от размеров, первая кнопка нажимается и действует, вторая после нажатия исчезает.<br />Dll не качал, заменил на случайный exe с иконками.<br />Не очень понимаю, зачем вам ф-ия добавления контролов. Разве что вы собираетесь показывать gui с заранее неизвестным их кол-вом(?).</p>]]></content>
			<author>
				<name><![CDATA[stealzy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=31937</uri>
			</author>
			<updated>2017-04-01T08:09:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114480#p114480</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114476#p114476" />
			<content type="html"><![CDATA[<p><strong>YMP</strong>, спасибо! Был неправ когда убрал плюсики.</p><p>Подкорректировал оба шикарных (на мой взгляд) варианта (исправил свои предыдущие 2 поста).<br />Остался только вопрос про нелогичную связь между размером и действием. Хотя, м.б. просто маленький баг AHK?</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2017-03-31T19:50:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114476#p114476</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114459#p114459" />
			<content type="html"><![CDATA[<p>2. Добавление стиля к уже существующим вместо замены их на него. Если мой склероз меня не подводит.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2017-03-31T14:41:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114459#p114459</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114450#p114450" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Функция Ваша - решать Вам. Исправления, которые я внес, рассчитаны на то, чтобы мне указали на ошибки и неверный подход.</p><p><strong>Malcev</strong><br />Ваш вариант не менее интересен - в коллекцию! Но та же проблема при динамическом добавлении кнопок, что и у <strong>teadrinker</strong>. Поправил сам. Жду замечаний.</p><div class="codebox"><pre><code>SetWorkingDir, % A_ScriptDir
global IcoDll
IcoDll := &quot;ClipMgrIcons.dll&quot;
If !FileExist(IcoDll) ; Загрузка библиотеки иконок при её отсутствии
	URLDownloadToFile, http://content.screencast.com/users/teadrinker/folders/Files/media/7d4f94ae-cdd3-467d-b3d1-786f5e8af91c/ClipMgrIcons.dll?downloadOnly=true, % IcoDll

Menu, Tray, Icon, %IcoDll%, 4 ; Иконка в заголовке окна и трее
Gui, Show, w200 h70
AddPicButton(8, 8, 32, 1, &quot;Action1&quot;)
AddPicButton(60, 8, 16, 2, &quot;Action2&quot;)
Return

; Функция добавляет &quot;кнопку&quot; с графическим рисунком
AddPicButton(x, y, size, n, action, GuiID := 1)  {
	global
	WS_EX_CLIENTEDGE := 0x200, WS_EX_DLGMODALFRAME := 0x1

	sizeDown := size + 2
	Gui, %GuiID%: Add, Pic, x%x% y%y% w%sizeDown% h-1 +E%WS_EX_CLIENTEDGE% hidden Icon%n% vDown%Action%, % IcoDll ; Вдавленная кнопка (скрываем)
	Gui, %GuiID%: Add, Pic, x%x% y%y% w%size% h-1 +E%WS_EX_DLGMODALFRAME% Icon%n% v%Action% gAnimation, % IcoDll ; Отжатая кнопка (показываем)
}

Animation: ; Обработка нажатия на кнопку
	GuiControl, %A_Gui%: Hide, %A_GuiControl%
	GuiControl, %A_Gui%: Show, Down%A_GuiControl%
	KeyWait, LButton
	GuiControl, %A_Gui%: Show, %A_GuiControl%
	MouseGetPos,,,, ControlID, 2
	GoTo %A_GuiControl%
Return

Action1:
	MsgBox This Action1
Return

Action2:
	AddPicButton(94, 8, 16, 6, &quot;Action3&quot;)
	GuiControl, 1: Hide, %A_GuiControl%
	GuiControl, 1: Hide, Down%A_GuiControl%
Return

Action3:
	MsgBox This Action3
Return

GuiClose:
	ExitApp</code></pre></div><p><strong>All</strong><br />Остались вопросы:<br />1. Если разница между <span style="color: blue">sizeDown</span> и <span style="color: blue">size</span> меньше 1 пикселя, то кнопки нажимаются, но Action почему то не работают. При чем тут размер???<br />2. Зафигом перед <span style="color: blue">E%WS_EX_CLIENTEDGE%</span> Вы ставите <span style="color: blue">+</span> ?</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2017-03-31T11:07:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114450#p114450</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114448#p114448" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>mozers пишет:</cite><blockquote><p>Может в коллекцию ?</p></blockquote></div><p> Не уверен, что здесь есть что-то интересное для коллекции, но если функция претендует на универсальность, она точно не должна использовать никаких глобальных переменных.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-03-31T10:13:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114448#p114448</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114446#p114446" />
			<content type="html"><![CDATA[<p><strong>stealzy</strong>, почему один?<br /></p><div class="codebox"><pre><code>SetWorkingDir, % A_ScriptDir
IcoDll := &quot;ClipMgrIcons.dll&quot;
if !FileExist(IcoDll)
   URLDownloadToFile, http://content.screencast.com/users/teadrinker/folders/Files/media/7d4f94ae-cdd3-467d-b3d1-786f5e8af91c/ClipMgrIcons.dll?downloadOnly=true, % IcoDll

Menu, Tray, Icon, %IcoDll%, 4

AddPicButton(8, 8, 32, IcoDll, 1, &quot;Action1&quot;)
AddPicButton(60, 8, 32, IcoDll, 6, &quot;Action2&quot;)
Gui, Show
return

AddPicButton(x, y, size, IcoDll, n, action, GuiID := 1)  {
   Global
   WS_EX_CLIENTEDGE := 0x200, WS_EX_DLGMODALFRAME := 0x1
   
   sizeDown := size + 2
   Gui, %GuiID%: Add, Pic, x%x% y%y% w%sizeDown% h%sizeDown% +E%WS_EX_CLIENTEDGE% Icon%n% v%Action% gAnimation, % IcoDll
   Gui, %GuiID%: Add, Pic, x%x% y%y% w%size% h%size% hwndh%Action% +E%WS_EX_DLGMODALFRAME% Icon%n% vUp%Action%, % IcoDll
}

Animation:
GuiControl, %A_Gui%: Hide, Up%A_GuiControl%
KeyWait, LButton
GuiControl, %A_Gui%: Show, Up%A_GuiControl%
MouseGetPos,,,, ControlID, 2
if (ControlID = h%A_GuiControl%)
   GoTo %A_GuiControl%
return

Action1:
msgbox Action1
return

Action2:
msgbox Action2
return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-03-31T09:16:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114446#p114446</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114442#p114442" />
			<content type="html"><![CDATA[<p>Проблемки выявились при попытке динамически добавить/скрыть кнопку. Поправил код. Есть замечания? Может в коллекцию ? Вроде штука то - востребованная... </p><div class="codebox"><pre><code>FileInstall, ClipMgrIcons.dll, ClipMgrIcons.dll
global IcoDll
IcoDll := A_ScriptDir &quot;\ClipMgrIcons.dll&quot;
if !FileExist(IcoDll) ; Загрузка библиотеки иконок при её отсутствии
	URLDownloadToFile, % &quot;http://content.screencast.com/users/teadrinker/folders/Files/media/7d4f94ae-cdd3-467d-b3d1-786f5e8af91c/ClipMgrIcons.dll?downloadOnly=true&quot;, % IcoDll

; Иконка в заголовке окна и трее
Menu, Tray, Icon, %IcoDll%, 4
Gui, Show, w200 h70

AddPicButton(8, 8, 32, 1, &quot;Action1&quot;)
global hButton2 ; указатель на эту кнопку используется в нашем Action2
hButton2 := AddPicButton(60, 8, 16, 2, &quot;Action2&quot;)
Return

; Функция добавляет &quot;кнопку&quot; с графическим рисунком и возвращает указатель на неё
AddPicButton(x, y, size, n, action, GuiID := 1) {
	static WS_EX_CLIENTEDGE := 0x200, WS_EX_DLGMODALFRAME := 0x1

	sizeDown := size + 2
	Gui, %GuiID%: Add, Pic, x%x% y%y% w%sizeDown% h-1 hwndhButtonDown +E%WS_EX_CLIENTEDGE% hidden Icon%n%, % IcoDll ; Вдавленная кнопка (скрываем)
	Gui, %GuiID%: Add, Pic, x%x% y%y% w%size% h-1 hwndhButtonUp +E%WS_EX_DLGMODALFRAME% Icon%n%, % IcoDll ; Отжатая кнопка (показываем)
	handler := Func(&quot;OnClick&quot;).Bind(hButtonUp, hButtonDown, action, GuiID)
	GuiControl, +g, % hButtonUp, % handler
	Return hButtonUp
}
; Обработка нажатия на кнопку
OnClick(IdButtonUp, IdButtonDown, action, GuiID) {
	GuiControl, %GuiID%: Hide, % IdButtonUp
	GuiControl, %GuiID%: Show, % IdButtonDown
	KeyWait, LButton
	GuiControl, %GuiID%: Hide, % IdButtonDown
	GuiControl, %GuiID%: Show, % IdButtonUp
	MouseGetPos,,,, ControlID, 2
	( ControlID = IdButtonUp &amp;&amp; Func(action).Call() )
}

Action1() {
	MsgBox, This Action1
}

Action2() {
	AddPicButton(94, 8, 16, 6, &quot;Action3&quot;)
	GuiControl, 1: Hide, % hButton2
}

Action3() {
	MsgBox, This Action3
}

GuiClose:
	ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2017-03-31T08:13:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114442#p114442</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114432#p114432" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, такую ф-ию можно будет вызвать только один раз <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" />. В 6 сообщении писал почему.</p>]]></content>
			<author>
				<name><![CDATA[stealzy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=31937</uri>
			</author>
			<updated>2017-03-31T03:05:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114432#p114432</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114427#p114427" />
			<content type="html"><![CDATA[<p>Можно сохранить их функциональность объявив в функции все переменные глобальными.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-03-30T19:57:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114427#p114427</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114426#p114426" />
			<content type="html"><![CDATA[<p><strong>mozers</strong>, в 17 сообщении вы в пятый раз наступили на те же грабли - := ожидает выражение, а строку ожидает =.<br />Не уверен, что = справится с пробелами, так что лучше перепишите как выражение.<br />Переменные про кот. ругается <em>интерпретатор </em> - это v<span style="color: green">State</span> и g<span style="color: green">Button</span>.<br />Как видите, я их просто выкинул, а <strong>teadrinker</strong> нашел обходной путь, для сохранения их функциональности.</p>]]></content>
			<author>
				<name><![CDATA[stealzy]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=31937</uri>
			</author>
			<updated>2017-03-30T19:22:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114426#p114426</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114425#p114425" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, да, спасибо, помогло! Только в этом варианте анимация нажатия отсутствует (тупо клик по картинке).</p>]]></content>
			<author>
				<name><![CDATA[mozers]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=4112</uri>
			</author>
			<updated>2017-03-30T18:59:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114425#p114425</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Button с картинкой (функция)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=114424#p114424" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>mozers пишет:</cite><blockquote><p>Вариант stealzy, конечно, проще и компактнее, но он не работает. Функция игнорирует все передаваемые параметры и лепит пустышки.</p></blockquote></div><p>Чтобы не ингорировала объявите IcoDll глобальной.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2017-03-30T18:25:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=114424#p114424</id>
		</entry>
</feed>
