Jump to content

Could Opt("GUICloseOnESC", 1) caue WinKill immunity?


Recommended Posts

Hello Peoples!!

Firstly let me say thanks in advance for any assistance rendered.

Sorry if the title is a bit misleading, best I could come up with at the time.

Here is the problem, as I understand it anyway....

I have been developing (mainly learning from) scripts "B", "C" & "D" over quite a long period of time for daily use at work. I have got all three to the point where they are almost finished and decided that I would create script "A" as kind of launcher and active GUI management bar with some additional goodies that don't really fit with any of the others.

Launching, minimising, hiding etc were quite straight forward using "Run" , "WinExists", "WinSetState" and the like and all was going well until it came to actually closing out of everything. This is where I found that script "D" would not close like the others.

I narrowed it down to script "D" using:

Opt("GUICloseOnESC", 0) ;1=ESC  closes, 0=ESC won't close

Once this option was set to 1 or commented out the problem went away.

It really handy set to 1 for script "D" due to the annoying web-based app that it deal with so the solution I have used is combining all the scripts into one (and to my suprise it is all still working as far as I can tell) but with 15000 lines of code it has become confusing for a beginner like me to work on, even when I seperated the functions into there own include.

So what I would really like to know is if there is a way to WinKill another script set to not close on ESC?

EDIT: Wow I really screwed up the thread title, it should say "Opt("GUICloseOnESC", 0)" as it does in the body.

Edited by Woongjinn
Link to comment
Share on other sites

Interesting! I confirmed it with both WinKill() and WinClose(). Neither works on windows with GUICloseOnEsc = 0.

#include <GuiConstantsEx.au3>

If Not @Compiled Then
    MsgBox(16, "Must run compiled", "Must run compiled")
    Exit
EndIf

; Create four windows then try to close them

If $CmdLine[0] Then
    ; Instance called to create window

    $n = Number($CmdLine[1])
    Opt("GuiCloseOnEsc", Mod($n, 2)) ; Odd = 1, Even = 0

    $hGUI = GUICreate("GUI_" & $n, 200, 200, $n * 200, $n * 200)
    $ctrlExit = GUICtrlCreateButton("Exit", 50, 85, 100, 30)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $ctrlExit
                Exit
        EndSwitch
    WEnd
Else
    ; Run test

    ; Open four windows
    For $n = 1 To 4
        ShellExecute(@ScriptFullPath, $n)
        Sleep(2000)
    Next

    ; Close four windows
    For $n = 1 To 4
        WinClose("GUI_" & $n, "")
        TrayTip("Test", "Closed: GUI_" & $n, 5)
        Sleep(3000)
    Next
EndIf

Hmm...

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Interesting! I confirmed it with both WinKill() and WinClose(). Neither works on windows with GUICloseOnEsc = 0.

#include <GuiConstantsEx.au3>

If Not @Compiled Then
    MsgBox(16, "Must run compiled", "Must run compiled")
    Exit
EndIf

; Create four windows then try to close them

If $CmdLine[0] Then
    ; Instance called to create window

    $n = Number($CmdLine[1])
    Opt("GuiCloseOnEsc", Mod($n, 2)) ; Odd = 1, Even = 0

    $hGUI = GUICreate("GUI_" & $n, 200, 200, $n * 200, $n * 200)
    $ctrlExit = GUICtrlCreateButton("Exit", 50, 85, 100, 30)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $ctrlExit
                Exit
        EndSwitch
    WEnd
Else
    ; Run test

    ; Open four windows
    For $n = 1 To 4
        ShellExecute(@ScriptFullPath, $n)
        Sleep(2000)
    Next

    ; Close four windows
    For $n = 1 To 4
        WinClose("GUI_" & $n, "")
        TrayTip("Test", "Closed: GUI_" & $n, 5)
        Sleep(3000)
    Next
EndIf

Hmm...

;)

Well thanks for confirming that it is not something I am doing wrong!!

At the moment I have combined it all into two seperate scripts which is manageable for me and allowing me to set GUICloseOnEsc = 0 on the two that need it the most. However the more I think about the amount of stray 'esc' key presses being thrown around (by me) the more practical it would be to have it on anything I use at work.

I was kind of expecting complications when they released the "new web-based system" that they have been working on for 5 years and will only work properly with IE6. They even managed to somehow totally fail at auto-complete to the point it took longer everytime you did anything.

The old system was telnet based and we got along fine!!

Anyway do you think there would be any value in posting this as a possible bug? or is it less than obvious design intention?

Thanks

Link to comment
Share on other sites

Give it a day to see if some of the smarter people see something in this topic we missed. Else, it's worth a BugTrack to see.

Any time you post a possible bug, however, make your demo script as short, simple and to the point as possible. Demonstrate the specific AutoIt symptom, without reference to any irrelevant specifics about your environment. If you show some effort at isolating the problem down to the basic issue and it's not a bug, you'll get a simple "No Bug" result.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Same problem if not compiled. Expected, but just in case. Same problem for WinKill.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=esc0.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GuiConstantsEx.au3>
$AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir");installDir for production


; Create four windows then try to close them

If $CmdLine[0] Then
    ; Instance called to create window

    $n = Number($CmdLine[1])
    Opt("GuiCloseOnEsc", Mod($n, 2)) ; Odd = 1, Even = 0

    $hGUI = GUICreate("GUI_" & $n, 200, 200, $n * 200, $n * 200)
    $ctrlExit = GUICtrlCreateButton("Exit", 50, 85, 100, 30)
    GUISetState()

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $ctrlExit
    Exit
    EndSwitch
    WEnd
Else
    ; Run test

    ; Open four windows
    For $n = 1 To 4
    If Not @Compiled Then
    ;create the script to run from the original; we will pretend we're running the original script
    $ToRun = '"' & $AutoItProdexePath & '\AutoIt3.exe "' & ' "' & @ScriptFullPath & '" ' & $n
    Run($ToRun)
    Else
    ShellExecute(@ScriptFullPath, $n)
    EndIf
    ;Sleep(2000)
    Next
 Sleep(2000)
    ; Close four windows
    For $n = 1 To 4
    WinClose("GUI_" & $n, "")
    TrayTip("Test", "Closed: GUI_" & $n, 5)
    Sleep(1000)
    Next

    For $n = 1 To 4
    If WinExists("GUI_" $ $n) then WinKill("GUI_" & $n, "")
    TrayTip("Test", "Closed: GUI_" & $n, 5)
    Sleep(1000)
    Next
EndIf

Behaves as when you register WM_CLOSE and do not return $GUI_RUNDEFMSG.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 weeks later...

It can be reproduced without external process:

#include <GUIConstantsEx.au3>

Opt("GUICloseOnESC", 0)

$hGUI = GUICreate("Test Script", 300, 200)

GUISetState(@SW_SHOW, $hGUI)

WinClose($hGUI)
WinKill($hGUI)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

And BTW, we can workaround this by sending Alt+F4 to the window:

ControlSend($hGUI, "", "", "!{F4}")

Or by cathing the WM_CLOSE message (wich is the best solution, it will cover up all the external attempts to close the window):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUICloseOnESC", 0)

$hGUI = GUICreate("Test Script", 300, 200)

GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_CLOSE, "WM_CLOSE")

WinClose($hGUI)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func WM_CLOSE($hWnd, $nMsg, $lParam, $wParam)
    Exit
EndFunc

P.S

As we can see here, when we set GUICloseOnESC = 0, the WM_CLOSE message is still recieved, so the problem is in the GUIGetMsg() (in the event handler actualy, because with OnEvent mode it's the same).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...