Jump to content

Detect how window was closed?


Recommended Posts

Is it for a AutoIt GUI or an external window ?

For a GUI made with AutoIt, you can try something like this :

#include <WindowsConstants.au3>
#include <Misc.au3>

Global Const $SC_CLOSE = 0xF060
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

GUICreate("gui")
Local $msg
Local $exit = GUICtrlCreateButton("Exit", 10, 10, 200, 25)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $exit
            ConsoleWrite("Closed with Exit button" & @CRLF)
            Exit
    EndSwitch
WEnd



Func WM_SYSCOMMAND($hWndGUI, $MsgID, $WParam, $LParam)
    If $WParam = $SC_CLOSE Then
        If _IsPressed("12") And _IsPressed("73") Then
            ConsoleWrite("Closed with ALT + F4" & @CRLF)
        ElseIf _IsPressed("1B") Then
            ConsoleWrite("Closed with ESC" & @CRLF)
        Else
            ConsoleWrite("Closed with X " & @CRLF)
        EndIf

        Exit
    EndIf
EndFunc
Edited by jguinch
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...