<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Управление функцией, при помощи параметра другой функции]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=14286</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14286&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Управление функцией, при помощи параметра другой функции».]]></description>
		<lastBuildDate>Tue, 30 Oct 2018 07:21:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=129564#p129564</link>
			<description><![CDATA[<p><strong>ponomarev.cs</strong>, что здесь мудреного?</p>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Tue, 30 Oct 2018 07:21:07 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=129564#p129564</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=129560#p129560</link>
			<description><![CDATA[<p><strong>MandarinKa02</strong><br />Спасибо. Попробую разобраться. Хотя, выглядит, как-то чересчур мудрёно.</p>]]></description>
			<author><![CDATA[null@example.com (ponomarev.cs)]]></author>
			<pubDate>Mon, 29 Oct 2018 23:39:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=129560#p129560</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=129558#p129558</link>
			<description><![CDATA[<div class="codebox"><pre><code>fn:=Func(&quot;my_function&quot;)

id:=_MenuManager(&quot;create&quot;)
_MenuManager(&quot;newitem&quot;,id,&quot;firefox&quot;,{title:&quot;Mozilla Firefox&quot;,callback:fn})
_MenuManager(&quot;newitem&quot;,id,&quot;chrome&quot;,{title:&quot;Google Chrome&quot;,callback:fn,icon:&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;})

_MenuManager(&quot;setmenu&quot;,id) ;В трей
Return
f1::reload
return

my_function(what=0,title=0) {
	msgbox % what
	chrome:=&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;
	firefox:=&quot;C:\Program Files\Mozilla Firefox\firefox.exe&quot;
	if (what=&quot;firefox&quot;) {
		try Run, % firefox

	} else if(what=&quot;chrome&quot;) {
		try Run, % chrome
	}
}


_MenuManager(func,id=0,name=0,value=0) {
	static menus:=[],n:=0
	if (func=&quot;create&quot;) {
		menus[++n]:=[]
		return n
	} else if(func=&quot;newitem&quot;) {
		if(!_MenuManager(&quot;getIndex&quot;,id))
			return 0
		menus[id][name]:=value
		return 1
	} else if(func=&quot;delitem&quot;) {
		if(!_MenuManager(&quot;getIndex&quot;,id))
			return 0
		menus[id].Delete(name)
		return 1
	} else if(func=&quot;getIndex&quot;) {
		for i in menus
			if(i=id)
				return i
		return 0
	} else if(func=&quot;setmenu&quot;) {
		if(!_MenuManager(&quot;getIndex&quot;,id))
			return 0
		Menu, Tray, NoStandard
		Menu, Tray, DeleteAll
		for name,obj in menus[id] {
			fn:=obj.callback
			Menu, Tray, Add,  % obj.title, % fn
			if(obj.icon)
				try Menu, Tray, Icon, % obj.title, % obj.icon,,
		} return 1
	}
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (MandarinKa02)]]></author>
			<pubDate>Mon, 29 Oct 2018 22:24:13 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=129558#p129558</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=129557#p129557</link>
			<description><![CDATA[<p>Хочу сделать код, который формирует пункты меню, более компактным, при этом чтобы пути к EXE файлам и иконкам хранились в переменных.<br />В результате сделал две простые функции:<br />StMenu - для пунктов меню, которые используют иконку EXE файла.<br />StMenuCI - для пунктов меню, которые используют сторонние иконки.</p><p>Пример:</p><div class="codebox"><pre><code>Menu, progs, UseErrorLevel

chrome:=&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;
firefox:=&quot;C:\Program Files\Mozilla Firefox\firefox.exe&quot;

StMenu(&quot;Mozilla Firefox&quot;, &quot;firefox&quot;, &quot;progs&quot;)
StMenu(&quot;Google Chrome&quot;, &quot;chrome&quot;, &quot;progs&quot;)
StMenuCI(&quot;Mozilla Firefox Custom Icon&quot;, &quot;firefox&quot;, chrome, &quot;&quot;, &quot;&quot;, &quot;progs&quot;)
Return

chrome:
try Run, %chrome%
Return

firefox:
try Run, %firefox%
Return

VK5D::Menu, progs, Show ; Menu Key
return

StMenu(itemname, handlername, menuname){
	Menu, %menuname%, Add, %itemname%, %handlername%
	iconpath:=%handlername%
	Menu, %menuname%, Icon, %itemname%, %iconpath%,,
}
return

StMenuCI(itemname, handlername, iconpath, n1, n2, menuname){
	Menu, %menuname%, Add, %itemname%, %handlername%
	Menu, %menuname%, Icon, %itemname%, %iconpath%,%n1%,%n2%
}
return</code></pre></div><p>Как правильно добавить ту часть кода, которая отвечает за запуск EXE в функцию, и возможно ли управлять ею через параметр?<br />Т.е. допустим у нас есть функция StMenuH и есть параметр, значение которого содержит путь к EXE файлу. Как его передать второй функции Handler? Или, быть может есть другой способ, как это всё правильно объединить?</p><p>Если сделать так, то при выборе любого пункта, будет запускаться EXE который соответствует последнему пункту меню. <br /></p><div class="codebox"><pre><code>Menu, progs, UseErrorLevel

chrome:=&quot;C:\Program Files (x86)\Google\Chrome\Application\chrome.exe&quot;
firefox:=&quot;C:\Program Files\Mozilla Firefox\firefox.exe&quot;

StMenuH(&quot;Mozilla Firefox&quot;, &quot;firefox&quot;, &quot;progs&quot;)
StMenuH(&quot;Google Chrome&quot;, &quot;chrome&quot;, &quot;progs&quot;)
Return

VK5D::Menu, progs, Show ; Menu Key
return

StMenuH(itemname, handlername, menuname){
	Global
	Menu, %menuname%, Add, %itemname%, Handler
	iconpath:=%handlername%
	Menu, %menuname%, Icon, %itemname%, %iconpath%,,
}
return

Handler()  {
	Global
	try Run, %iconpath%
}</code></pre></div><p>P.S.Пока только изучаю возможности AHK и стандартного меню, так что сразу извиняюсь если код выглядит как очередной кривой велосипед.</p>]]></description>
			<author><![CDATA[null@example.com (ponomarev.cs)]]></author>
			<pubDate>Mon, 29 Oct 2018 19:42:39 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=129557#p129557</guid>
		</item>
	</channel>
</rss>
