Modify

Opened 15 years ago

Closed 15 years ago

#1794 closed Bug (No Bug)

Opt("GuiCloseOnESC", 0) causes WinClose() to be ignored

Reported by: AndyS01@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.6.1 Severity: None
Keywords: GuiCloseOnESC, WinCLose(), WinKill() Cc:

Description

When a script is compiled with Opt("GuiCloseOnESC", 0) active, another script, after getting its handle cannot close the first script. The WinClose() returns an OK status, but it really doesn't work. Compiling the first script with Opt("GuiCloseOnESC", 1) avtive works OK.

To reproduce: compile the test script, below; open a DOS window; run the compiled script; run the compiled script again. This time, there will be an error MsgBox complaining that the instance was not killed.

Change Opt("GuiCloseOnESC", 0) to Opt("GuiCloseOnESC", 1) and run the reproduce steps again. This time it works OK.

Test script:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

[b]Opt("GuiCloseOnESC", 0)[/b]
Global $sCurrentTitle = "Test WinClose()"

runUnique() ; Kill off any currently running version of this script

$hGUI = GUICreate($sCurrentTitle, 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 2, 2, 296, 196, $LVS_REPORT)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, @HOUR & ":" & @MIN & ":" & @SEC & " - " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
exit (1)

Func runUnique()
    Local $hWnd, $res, $title = $sCurrentTitle

    if (WinActivate($title, "") <> 0) Then
        $hWnd = WinGetHandle($title, "")
        If (Not IsHWnd($hWnd)) Then $hWnd = HWnd($hWnd)
        if (IsHWnd($hWnd)) Then
            $res = WinClose($hWnd)
            if ($res == 0) Then
                ConsoleWrite("+++: WinClose() failed")
                $res = WinKill($hWnd)
                ConsoleWrite("+++: WinKill() returned " & $res & @CRLF)
                if ($res == 0) Then
                    ConsoleWrite("+++: WinKill() failed")
                EndIf
            EndIf

            if (WinActivate($title, "") <> 0) Then
                MsgBox(0, "ERROR", "Cannot kill window")
            Else
                MsgBox(0, "INFO", "Killed other window")
            EndIf
        Else
            MsgBox(0, "ERROR", "Cannot get win handle")
        EndIf
    EndIf
EndFunc   ;==>runUnique

Attachments (0)

Change History (4)

comment:1 by MrCreatoR <mscreator@…>, 15 years ago

Too much complicated, here is a more simple reproducing script:

Opt("GUICloseOnESC", 0)

$sTitle = "Test WinClose()"

;Kill off any currently running version of this script
If WinExists($sTitle) Then
	If Not WinClose($sTitle) Then WinKill($sTitle)
	
	If WinExists($sTitle) Then
		MsgBox(0, "ERROR", "Cannot kill window")
	EndIf
EndIf

GUICreate($sTitle, 300, 200)
GUISetState()

Do
Until GUIGetMsg() = -3

no need to compile or anything else, just run the script twice, it should close the previous GUI, but it doesn't. BTW, it's only with AutoIt GUI, other winows closing fine.

comment:2 by MrCreatoR <mscreator@…>, 15 years ago

I think it's a problem in the option name/description, it should be something like this:
Opt("GUIClose", 0)
Because it's blocking the window from been closed by external application. Althought it could be handy, and we can always use GUISetAccelerators to prevent GUI closing by ESC.

comment:3 by BrewmanNH, 15 years ago

I also found out that you can't TaskKill the program from a command line unless you use the /f (Force terminate) command line switch with taskkill if the script includes the Opt("GUICloseOnESC", 0) option.

comment:4 by Jon, 15 years ago

Resolution: No Bug
Status: newclosed

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.