<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Управление функцией, при помощи параметра другой функции]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14286&amp;type=atom" />
	<updated>2018-10-30T07:21:07Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14286</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129564#p129564" />
			<content type="html"><![CDATA[<p><strong>ponomarev.cs</strong>, что здесь мудреного?</p>]]></content>
			<author>
				<name><![CDATA[MandarinKa02]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34409</uri>
			</author>
			<updated>2018-10-30T07:21:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129564#p129564</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129560#p129560" />
			<content type="html"><![CDATA[<p><strong>MandarinKa02</strong><br />Спасибо. Попробую разобраться. Хотя, выглядит, как-то чересчур мудрёно.</p>]]></content>
			<author>
				<name><![CDATA[ponomarev.cs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39609</uri>
			</author>
			<updated>2018-10-29T23:39:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129560#p129560</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129558#p129558" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[MandarinKa02]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34409</uri>
			</author>
			<updated>2018-10-29T22:24:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129558#p129558</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Управление функцией, при помощи параметра другой функции]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129557#p129557" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[ponomarev.cs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39609</uri>
			</author>
			<updated>2018-10-29T19:42:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129557#p129557</id>
		</entry>
</feed>
