Find Process Add Picture

Get help with using AutoHotkey and its commands and hotkeys
Epialis
Posts: 518
Joined: 02 Aug 2020, 22:44

Find Process Add Picture

18 Aug 2020, 22:27

Okay, once again...

How about a way to click on add.... it opens up a window for you to search a process, or exe... click on the file.... click add and it adds the link to the program to an existing picture?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Find Process Add Picture

20 Aug 2020, 17:32

Hi,

I've you tried something Epialis? If so, what is not working, where you get stuck specifically ? Have you already some code, albeit a pseudo-code? :)
Epialis wrote:
18 Aug 2020, 22:27
How about a way to click on add.... it opens up a window for you to search a process, or exe... click on the file.... click add and it adds the link to the program to an existing picture?
FileSelectFile is probably the best way to go.

Here's a draft pseudo-code, I tried to keep it a simple as possible (see links to the doc in comments near the code) - hopefully it will help you as a starting point:

Code: Select all

#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force



paths := {} 
paths.AHK := {"pathToExe": "", "pathToPic": A_AHKPath}
paths.Notepad := {"pathToExe": "", "pathToPic": "notepad.exe"}
; https://www.autohotkey.com/docs/Objects.htm#Usage_Associative_Arrays

for program, obj in paths { ; https://www.autohotkey.com/docs/commands/For.htm
	Gui, Add, Picture, w50 h-1 glabelForPics v%program%, % obj.pathToPic ; https://www.autohotkey.com/docs/commands/GuiControls.htm#Picture
	GUI, Add, Button, wp glabelForButtons vB%program%, Add... ; https://www.autohotkey.com/docs/commands/Gui.htm#label
}
GUI, Show, AutoSize
return

labelForButtons:
	; MsgBox % A_GuiControl
	progName := SubStr(A_GuiControl, 2) ; remove the trailing b at the beginning of the control's associated variable (https://www.autohotkey.com/docs/commands/Gui.htm#var)
	; here you might want to use the FileSelectFile command instead (https://www.autohotkey.com/docs/commands/FileSelectFile.htm) in order to retrieve A_AHKPath, notepad.exe or whatever from user input
	if (progName = "Notepad")
		paths[ progName ].pathToExe := "notepad.exe" ; set the path to the given program
	else if (progName = "AHK")
		paths[ progName ].pathToExe := A_AHKPath ; set the path to the given program
return

labelForPics:
	; MsgBox % A_GuiControl
	path := paths[ A_GuiControl ].pathToExe
	if (path = "") { ; if no path has been registered for this picture...
		GUI, +OwnDialogs
		MsgBox, 64,, No path has been registered for this picture.
	return
	}
	; otherwise
	run % path,, UseErrorLevel
	if (ErrorLevel = "ERROR")
		MsgBox, 64,, Could not launch the program.
return

Cheers

A_AhkUser
my scripts

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, Bing [Bot], DaveT1, LakaiHigh, mikeyww, TXShooter and 59 guests