How to close GUI.exe after running a subroutine Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ScripterUser
Posts: 4
Joined: 24 Aug 2015, 04:43

How to close GUI.exe after running a subroutine

Post by ScripterUser » 22 Mar 2023, 18:13

Hello Community,

I have a small script with two buttons. How can I add a behavior that the compiled GUI.exe should close after returning from a subroutine?
The Idea is no matter which button is pressed the GUI should close completely even from the tray-icon-area.

I tried to figure it out but I could not find a solution.

Could you help me please?

Thank you.

Regards,
ScripterUser

Code: Select all

#SingleInstance, Force

Gui, Add, Button, x10 y+5 w250 h50 gSubroutine1, start Subroutine1
Gui, Add, Button, x10 y+5 w250 h50 gSubroutine2, start Subroutine2

Subroutine1:
	If !FileExist(A_ScriptDir . "\file1.txt")
    		{
		MsgBox, file: "file doesn't exist!
		}
	else
		{
		FileCopy, %A_ScriptDir%\file1.txt, %A_ScriptDir%\file_copy.txt, 1
		Msgbox, file copied!
		}
	return

Subroutine2:
	If !FileExist(A_ScriptDir . "\file2.txt")
    		{
		MsgBox, file: "file doesn't exist!
		}
	else
		{
		FileCopy, %A_ScriptDir%\file2.txt, %A_ScriptDir%\file_copy.txt, 1
		Msgbox, file copied!
		}
	return

^NumPad1::ExitApp ; This line will be removed later


[Mod action: Moved topic to v1 section. The main section is for v2.]

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: How to close GUI.exe after running a subroutine

Post by mikeyww » 22 Mar 2023, 19:40

Hello,

You are posting in the v2 forum.

Before the return, you can destroy the GUI.

If you don't show the GUI, then you will never see it.

Without any Return, your script will continue to the next statement. Follow your script line by line to see what it will do.

ScripterUser
Posts: 4
Joined: 24 Aug 2015, 04:43

Re: How to close GUI.exe after running a subroutine  Topic is solved

Post by ScripterUser » 23 Mar 2023, 18:40

Hi mikeyww,

sorry I didn't realize I was posting in the wrong area.

I am a beginner in autohotkey it is really trail and error for me.

I tried the destroy command and it didn't work.

I found another solution to get what I want.

I used the goto subroutine command to ExitApp.

Anyway, thank you for your support.

Example:

Code: Select all

#SingleInstance, Force

Gui, Add, Button, x10 y+5 w250 h50 gSubroutine1, start Subroutine1
Gui, Add, Button, x10 y+5 w250 h50 gSubroutine2, start Subroutine2

Subroutine1:
	If !FileExist(A_ScriptDir . "\file1.txt")
    		{
		MsgBox, file: "file doesn't exist!
		}
	else
		{
		FileCopy, %A_ScriptDir%\file1.txt, %A_ScriptDir%\file_copy.txt, 1
		Msgbox, file copied!
		}
	return

Subroutine2:
	If !FileExist(A_ScriptDir . "\file2.txt")
    		{
		MsgBox, file: "file doesn't exist!
		}
	else
		{
		FileCopy, %A_ScriptDir%\file2.txt, %A_ScriptDir%\file_copy.txt, 1
		Msgbox, file copied!
		}
	goto Subroutine_Close_GUI_After_buttons_pressed
	return

Subroutine_Close_GUI_After_buttons_pressed:
ExitApp

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: How to close GUI.exe after running a subroutine

Post by mikeyww » 23 Mar 2023, 19:27

I'm glad that you figured it out.

If you replace your Goto command with ExitApp, then you can simply delete everything that follows it.

Post Reply

Return to “Ask for Help (v1)”