Page 1 of 1

Update Gui Variables, Does this look right?

Posted: 23 Aug 2019, 10:42
by DMDComposer
Hi,

I'm still new to ahk and was wondering if I'm applying the below code correctly and/or there is a better way to do what I'm trying to achieve. Finally, is there a way to automatically figure out the width of the gui based on the NewGuiTitle?

How my script works: I have a huge script that contains all my shortcuts (one master file). I use basically this script below: To register a key command, listen for a 3 digit code, then run said script based on the 3 digit code.

I'd like to update the gui everytime the code is executed to just come up with a gui stating the title of the code executed. Leaving some properties default at times, but be able to adjust accordingly if need be. For example: change the color or width of the gui.

Here is my code for testing.

Code: Select all

;Gui Standard Settings called at beginning of script
DefaultGuiColor := "666666"  ; Can be any RGB color (it will be made transparent below).
DefaultGuiTitle := "Whacky Shortcuts" ;replace this with the title I want.
DefaultGuiSleepTime := 1500
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %DefaultGuiColor%
Gui, Font, s32  ; Set a large font size (32-point).
Gui,Add,Text,vCName cwhite,% DefaultGuiTitle
Gui, Show, x0 y882 NoActivate  ; NoActivate avoids deactivating the currently active window.
Sleep, %DefaultGuiSleepTime%
Gui, Hide

F15:: ;Key Command to start the script and listen for the next 3 digit input
input, command, L3 ; L3 to limit the input to 3 keys.

if command = 001 ;Run Program XXX
		Run, "Program XXX"
		;Update Gui
		NewGuiTitle := 610 ;Change with Command #
		NewGuiTitleDefaultGuiTitle := "XXX" ;Change Title
		GUI_Title_Width := 650 ;Change Title Width
		Gui, Show, W%GUI_Title_Width%
		Gui, Color, %DefaultGuiColor% ;Change Color of Gui
		GuiControl,,CName,% NewGuiTitleDefaultGuiTitle
		Sleep, %DefaultGuiSleepTime%
		Gui, Hide
		
else if command = 002 ;Run Program YYY
		Run, "Program YYY"
		NewGuiTitle := 611 ;Change with Command #
		NewGuiTitleDefaultGuiTitle := "Run YYY" ;Change Title
		GUI_Title_Width := 600 ;Change Title Width
		Gui, Show, W%GUI_Title_Width%
		Gui, Color, Red ;Change Color of Gui
		GuiControl,,CName,% NewGuiTitleDefaultGuiTitle
		Sleep, %DefaultGuiSleepTime%
		Gui, Hide
		
return