How to use 2GUIEscape in a function Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

How to use 2GUIEscape in a function

26 May 2018, 22:32

I have tried entering GUI, 2: for the appropriate lines in the second function FormulaWindow() but when I try using 2GuiEscape: it does not seem to process the instructions under it (UserInput := "You Escaped 2") but rather seems to carry out the instructions under the first GUIEscape (FormulaEntered := "You Escaped 1") in the function DialogBoxTwo. Here is the original code without the GUI, 2: corrections as when I tried it not only did the 2GuiEscape not work but other things broke as well such as the buttons.

Code: Select all

#q::EnterFormula()

EnterFormula(){
Loop
{
FormulaWindow(FormulaEntered, CancelCode)

 If(CancelCode = 1){
	FormulaEntered = 0
	break
	}
  Else{
    DialogBoxTwo(FormulaEntered, DialogChange)
	if (DialogChange = 2){
        continue
    }
	Else{
	break
    }
	}
    
}

MsgBox %FormulaEntered%

}


DialogBoxTwo(ByRef FormulaEntered, ByRef NeedChange){
Gui, +LastFound
GuiHWND := WinExist() 
Gui, Add, Button, x22 y69 w110 h40 Default, Continue
Gui, Add, Text, x62 y19 w190 h20 , Equation Entered: 
Gui, Add, Text, x122 y39 w40 h20 , %FormulaEntered%
Gui, Add, Button, x152 y69 w110 h40 , Change
; Generated using SmartGUI Creator 4.0
Gui, Show, x612 y377 h135 w290, Confirm

  WinWaitClose, ahk_id %GuiHWND%  ;--waiting for gui to close

  return      ;--returning value

ButtonContinue:
NeedChange = 1
Gui, Destroy ; Destroy the GUI to get it out of the way1
return

1GuiEscape:
FormulaEntered := "You Escaped 1"
NeedChange = 1
Gui, Destroy ; Destroy the GUI to get it out of the way1
return

ButtonChange: ; Execute the following actions when the button from the GUI Change is pressed
NeedChange = 2
Gui, Destroy ; Destroy the GUI to get it out of the way
return
}

FormulaWindow(ByRef UserInput, ByRef ToCancel){
Global FUserInput
Gui, +LastFound
GuiHWND2 := WinExist()
Gui, Add, Button, x42 y129 w110 h30 Default, OK
Gui, Add, Button, x162 y129 w110 h30 , Cancel
Gui, Add, Button, x282 y129 w110 h30 , Clear

; Note that v is the convention used to denote the variable below but the actual variable saved is without the v as just UserInput
Gui, Add, Edit, x42 y89 w350 h20 vFUserInput,
Gui, Add, Text, x14 y92 w22 h16 , y  =
Gui, Add, Text, x12 y9 w290 h20 , Enter an equation for Y as a function of X
Gui, Add, Text, x12 y29 w150 h20 , eg.    x + 1
Gui, Add, Text, x12 y49 w150 h20 , eg.    2*x + 3
; Generated using SmartGUI Creator 4.0
Gui, Show, x530 y255 h184 w411, Enter Equation
GuiControl, Focus, FUserInput
  WinWaitClose, ahk_id %GuiHWND2%  ;--waiting for gui to close

  return

ButtonOK: ; Execute the following actions when the button from the GUI OK is pressed
Gui, Submit ; Save all the information in the GUI (The variables)
UserInput = %FUserInput%
ToCancel = 2
Gui, Destroy ; Destroy the GUI to get it out of the way
Return

2GuiEscape:
UserInput := "You Escaped 2"
ToCancel = 1
Gui, Destroy ; Destroy the GUI to get it out of the way
return

ButtonCancel:
UserInput = 0
ToCancel = 1
Gui, Destroy ; Destroy the GUI to get it out of the way
Return

ButtonClear:
GuiControl, ,FUserInput
GuiControl, Focus, FUserInput
Return
}
`::exitapp
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: How to use 2GUIEscape in a function  Topic is solved

26 May 2018, 22:57

try naming your second gui "2"
like
gui, 2:add, stuff
gui, 2:font, something
gui, 2:show, somewhere
Archandrion
Posts: 31
Joined: 26 May 2018, 22:23

Re: How to use 2GUIEscape in a function

27 May 2018, 11:53

It worked this time. Not sure what I missed when I tried entering GUI, 2: the first time but 2GUIEscape: was still not working so I posted the code without it so that anyone replying could test it for functionality to see if it needed something other than just the GUI, 2: for the second GUIEscape to work correctly. Also I noticed that 1GuiEscape: did not work for GUI, 1: but rather GuiEscape:. Must have missed something in the documentation the first time round.

#q::EnterFormula()

EnterFormula(){
Loop
{
FormulaWindow(FormulaEntered, CancelCode)

If(CancelCode = 1){
break
}
Else{
DialogBoxTwo(FormulaEntered, DialogChange)
if (DialogChange = 2){
continue
}
Else{
break
}
}

}

MsgBox %FormulaEntered%

}


DialogBoxTwo(ByRef FormulaEntered, ByRef NeedChange){
Gui, 2:+LastFound
GuiHWND := WinExist()
Gui, 2:Add, Button, x22 y69 w110 h40 Default, Continue
Gui, 2:Add, Text, x62 y19 w190 h20 , Equation Entered:
Gui, 2:Add, Text, x122 y39 w40 h20 , %FormulaEntered%
Gui, 2:Add, Button, x152 y69 w110 h40 , Change
; Generated using SmartGUI Creator 4.0
Gui, 2:Show, x612 y377 h135 w290, Confirm

WinWaitClose, ahk_id %GuiHWND% ;--waiting for gui to close

return ;--returning value

2ButtonContinue:
NeedChange = 1
Gui, 2:Destroy ; Destroy the GUI to get it out of the way1
return

2GuiEscape:
FormulaEntered := "You GuiEscaped DialogBoxTwo"
NeedChange = 1
Gui, 2:Destroy ; Destroy the GUI to get it out of the way1
return

2ButtonChange: ; Execute the following actions when the button from the GUI Change is pressed
NeedChange = 2
Gui, 2:Destroy ; Destroy the GUI to get it out of the way
return
}

FormulaWindow(ByRef UserInput, ByRef ToCancel){
Global FUserInput
Gui, 1:+LastFound
GuiHWND2 := WinExist()
Gui, 1:Add, Button, x42 y129 w110 h30 Default, OK
Gui, 1:Add, Button, x162 y129 w110 h30 , Cancel
Gui, 1:Add, Button, x282 y129 w110 h30 , Clear

; Note that v is the convention used to denote the variable below but the actual variable saved is without the v as just UserInput
Gui, 1:Add, Edit, x42 y89 w350 h20 vFUserInput,
Gui, 1:Add, Text, x14 y92 w22 h16 , y =
Gui, 1:Add, Text, x12 y9 w290 h20 , Enter an equation for Y as a function of X
Gui, 1:Add, Text, x12 y29 w150 h20 , eg. x + 1
Gui, 1:Add, Text, x12 y49 w150 h20 , eg. 2*x + 3
; Generated using SmartGUI Creator 4.0
Gui, 1:Show, x530 y255 h184 w411, Enter Equation
GuiControl, Focus, FUserInput
WinWaitClose, ahk_id %GuiHWND2% ;--waiting for gui to close

return

ButtonOK: ; Execute the following actions when the button from the GUI OK is pressed
Gui, 1:Submit ; Save all the information in the GUI (The variables)
UserInput = %FUserInput%
ToCancel = 2
Gui, 1:Destroy ; Destroy the GUI to get it out of the way
Return

GuiEscape:
UserInput := "You GuiEscaped FormulaWindow"
ToCancel = 1
Gui, 1:Destroy ; Destroy the GUI to get it out of the way
return

ButtonCancel:
UserInput = "FormulaWindow Canceled"
ToCancel = 1
Gui, 1:Destroy ; Destroy the GUI to get it out of the way
Return

ButtonClear:
GuiControl, ,FUserInput
GuiControl, Focus, FUserInput
Return
}
`::exitapp

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], flyingDman, Odlanir, philippelo, Pilu and 150 guests