How to close my Gui but not end my Script itself.. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahkAndSteak
Posts: 10
Joined: 01 Apr 2022, 20:58

How to close my Gui but not end my Script itself..

Post by ahkAndSteak » 02 Jul 2022, 14:22

Hey, so I'm not sure why I haven't been able to resolve this by just forum searching, but haven't.

I have this script below, where I not only include some hotstring/hotkeys, but also have a GUI.

Right now the GUI only embeds a video.. but later, I want to display the values of many variables I plan to add to the script, thus I don't want to break the GUI out of this main script.

Rather keep it here in main.ahk.

I'll sum up the issue:
I want to be able to hit Control-F2, and the GUI pops up, where I can view variables, or play back the video.

But also want to be able to click the upper right X button, and thus dismiss it.

If I leave in the GuiClose:
Cancel:
ExitApp
in the script ( as you can see below, I have it commented it out ), then what happens is, the ExitApp completely stops running the entire script, and my hotkeys/hostring no longer works.

But if I remove the Exitapp, when I dismiss the GUI with the X button, the GUI window disappears,
but doesn't close its own resources.. so when I need the GUI again, I get an AHK error, that I can't start another instance of wmplayer, or similar.

So wondering how you handle having your GUI in your main script.



main.ahk

Code: Select all

 #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

#Warn  ; Enable warnings to assist with detecting common errors.

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

#SingleInstance, Force

SetWorkingDir, A_ScriptDir

 
^F2::

    Gui,1:Font, s12, Verdana  ; Set 10-point Verdana.

    file = myvideoiclip.mp4

    Gui,1:Add, ActiveX, x5 y2 w400 h232 vWmp, WMPLayer.OCX

    Wmp.Url := file

    Gui,1:Show, w1100 h503, Dashboard

    Return


;GuiClose:

;Cancel:

;ExitApp

 

 

 

::gpo::

    Sleep 250

    SendInput, git push origin

    return

 

::gcmd::

    Sleep 250

    SendInput, git commit -m `"

    SendInput, % jiranum  " - message "

    SendInput,  `"

    return

:*:reach::Thanks for reaching out
 

:*:jjira::

    Sleep 250

    SendInput % jiranum

    return

 

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: How to close my Gui but not end my Script itself..  Topic is solved

Post by boiler » 02 Jul 2022, 14:54

Don’t create the GUI inside your hotkey subroutine. Just show it.

Code: Select all

 #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

#Warn  ; Enable warnings to assist with detecting common errors.

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

#SingleInstance, Force

SetWorkingDir, A_ScriptDir

Gui,1:Font, s12, Verdana  ; Set 10-point Verdana.

file = myvideoiclip.mp4

Gui,1:Add, ActiveX, x5 y2 w400 h232 vWmp, WMPLayer.OCX

Wmp.Url := file

return
 
^F2::Gui,1:Show, w1100 h503, Dashboard

;GuiClose:

;Cancel:

;ExitApp

 

 

 

::gpo::

    Sleep 250

    SendInput, git push origin

    return

 

::gcmd::

    Sleep 250

    SendInput, git commit -m `"

    SendInput, % jiranum  " - message "

    SendInput,  `"

    return

:*:reach::Thanks for reaching out
 

:*:jjira::

    Sleep 250

    SendInput % jiranum

    return


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

Re: How to close my Gui but not end my Script itself..

Post by mikeyww » 02 Jul 2022, 14:54

Editing concurrently with boiler....

Things you can do with GUI: Show, Hide, Destroy.

By default (without GuiClose subroutine), clicking the "X" is equivalent to Gui, Hide. Once hidden, you can show the same GUI again whenever you like.

ahkAndSteak
Posts: 10
Joined: 01 Apr 2022, 20:58

Re: How to close my Gui but not end my Script itself..

Post by ahkAndSteak » 02 Jul 2022, 15:15

Thanks guys for the help.
Boiler, I now realize I remember reading a post instructing to do that and it's now coming back. Thanks

ahkAndSteak
Posts: 10
Joined: 01 Apr 2022, 20:58

Re: How to close my Gui but not end my Script itself..

Post by ahkAndSteak » 02 Jul 2022, 17:34

I moved everything out of the ^F2 subroutine, except for the GUI Show as you suggested.

One extra thing i had to, though, was also move the Wmp.url assignment under the subroutine as well, so it looks like:

Code: Select all

^F2::
    Gui,Show, w1100 h503, Dashboard
    Wmp.Url := file
    Return
Otherwise, what happened, is that when I execute the script, without even hitting the ctrl-F2,
the wmplayer started the video clip in the background, but without video, and so you hear the audio.

All good now.

Post Reply

Return to “Ask for Help (v1)”