The first script works perfectly:
Main script:
Code: Select all
#SingleInstance force
;TestScript for Guis
F1::
title = Activated by F1
description = A MessageBox will apear and show the result
#include Guis\SimpleGui.ahk ; Include TestGui - Variable = input
MsgBox, %input%
return
Code: Select all
Gui -Caption +LastFound +ToolWindow +AlwaysOnTop ; borderless, last found, no taskbar icon, always on top
Gui, Add, Picture, x0 y0 w600 h240, %A_ScriptDir%\Guis\Standard.jpg ; Background image (Image)
Gui, Add, Text, BackgroundTrans Center x0 y10 w600 h30 cWhite, %title% ; Title of the script (Text)
Gui, Add, Text, BackgroundTrans x10 y60 w500 h90 cWhite, %description% ; Descriptions (Text)
Gui, Add, Edit, vInput x10 y85 w580 ; Input field (Edit)
Gui, Add, Button, Default x195 y150 w80 gOK, OK ; Proceed with script (Button)
Gui, Add, Button, x295 y150 w80 gCancel, Cancel ; Cancel script (Button)
Gui, Show, w600 h240, Gui-Inputbox ; Show Gui
GuiControl, Focus, Input ; Focus input field automatically
Hotkey, Enter, OK ; Pressing Enter = OK
Hotkey, Escape, Cancel ; Pressing Esc = Cancel (DOES NOT WORK)
return
Cancel: ; When Cancel was chosen:
Gui, Destroy ; Destroy Gui
return
OK: ; When OK was chosen:
Gui, Submit ; Submit data
Gui, Destroy ; Destroy Gui
- type in a word inside of the edit field
- I press OK and get the word shown in a MessageBox - perfect.
When I want to add another sub-script in the main script, which should also access this gui, it doesn't work.
Code: Select all
F2::
title = Activated by F2
description = A MessageBox will apear and show the result
#include Guis\SimpleGui.ahk ; Include TestGui - Variable = input
MsgBox, %input%
return
It seems I cannot include the same gui several times by using this method.
My next idea was to create a function inside of the SimpleGui.ahk
Code: Select all
Simple_Gui(title, description)
{
Gui -Caption +LastFound +ToolWindow +AlwaysOnTop ; borderless, last found, no taskbar icon, always on top
Gui, Add, Picture, x0 y0 w600 h240, %A_ScriptDir%\Guis\Standard.jpg ; Background image (Image)
Gui, Add, Text, BackgroundTrans Center x0 y10 w600 h30 cWhite, %title% ; Title of the script (Text)
Gui, Add, Text, BackgroundTrans x10 y60 w500 h90 cWhite, %description% ; Descriptions (Text)
Gui, Add, Edit, vInput x10 y85 w580 ; Input field (Edit)
Gui, Add, Button, Default x195 y150 w80 gOK, OK ; Proceed with script (Button)
Gui, Add, Button, x295 y150 w80 gCancel, Cancel ; Cancel script (Button)
Gui, Show, w600 h240, Gui-Inputbox ; Show Gui
GuiControl, Focus, Input ; Focus input field automatically
}
;Hotkey, Enter, OK ; Pressing Enter = OK - doesn't matter if commented out or in
;Hotkey, Escape, Cancel ; Pressing Esc = Cancel (DOES NOT WORK) - doesn't matter if commented out or in
Cancel: ; When Cancel was chosen:
Gui, Destroy ; Destroy Gui
return
OK: ; When OK was chosen:
Gui, Submit ; Submit data
Gui, Destroy ; Destroy Gui
Code: Select all
#SingleInstance force
;TestScript for Guis
F1::
#include Guis\SimpleGui.ahk ; Include TestGui - Variable = input
Simple_Gui("Activated by F1", "A MessageBox will apear and show the result") ; title, description | Variable = input
MsgBox, %input%
return
F2::
#include Guis\SimpleGui.ahk ; Include TestGui - Variable = input
Simple_Gui("Activated by F2", "A MessageBox will apear and show the result") ; title, description | Variable = input
MsgBox, %input%
return
How to do it correctly?
Or better: How to include the same gui several times?
I prefer not to paste the whole gui code, because my guis usually take a whole site and it becomes confusing more quickly.
At the moment, I'm working on different types of guis which I would like to implement in my main script whenever I need them.
Perhaps using classes?
Thanks for any help!
Best regards