Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to destroy gui on <MyGui>Escape #16

Open
oyhel opened this issue Sep 18, 2021 · 2 comments
Open

Unable to destroy gui on <MyGui>Escape #16

oyhel opened this issue Sep 18, 2021 · 2 comments

Comments

@oyhel
Copy link

oyhel commented Sep 18, 2021

I am fairly certain the syntax for destroying the gui on the press of the escape key is correct here, but it does not work. The form is properly destroyed when pressing the close button top right. Am I missing something here or is this a bug?

; Include the Neutron library
#Include ./libs/Neutron.ahk

MADRS(){
    
    ; Create a new NeutronWindow
    Madrs := new NeutronWindow()
    Madrs.Load("madrs-neutron.html")
    Madrs.Gui("+LabelNeutron")

    ; Show the GUI
    Madrs.Show("w1200 h1200 x2500 y500")

    ; Set focus to the form
    Madrs.doc.focus()
    WinActivate, % "madrs-neutron.ahk" Madrs.hWnd
    return
    
    MadrsEscape:
        MsgBox, "escape pressed" ;this does not show
        Madrs.Destroy()  ;this does not destroy the gui
        Return

    MadrsClose:
        Madrs.Destroy()
        Return
}

Huge thanks for your work!!

@SaifAqqad
Copy link
Contributor

The form is properly destroyed when pressing the close button top right

That's because the close button is calling the neutron.Close() function which is set as its onclick in the examples.

This should fix it :D

; Include the Neutron library
#Include ./libs/Neutron.ahk

MADRS(){
    
    ; Create a new NeutronWindow
    global Madrs := new NeutronWindow() ; <---- the window object should be global, if you want to access it in the labels
    Madrs.Load("madrs-neutron.html")
    ; Madrs.Gui("+LabelNeutron")  ; <---- this should match the prefix you're using in the 'Close' and 'Escape' labels
    Madrs.Gui("+LabelMadrs") ; like this

    ; Show the GUI
    Madrs.Show("w1200 h1200 x2500 y500")

    ; Set focus to the form
    Madrs.doc.focus()
    WinActivate, % "madrs-neutron.ahk" Madrs.hWnd
    return
    
    MadrsEscape:
        MsgBox, "escape pressed" ;this does not show
        Madrs.Destroy()  ;this does not destroy the gui
        Return

    MadrsClose:
        Madrs.Destroy()
        Return
}

@oyhel
Copy link
Author

oyhel commented Sep 27, 2021

Sorry for the late response, this works! Many thanks again! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants