Jump to content

Distinguishing between Esc, alt-f4 and X being clicked to close a gui window


DelStone
 Share

Recommended Posts

Hi

I've been racking my brains over this for a number of hours and can't spot anything in the forums to address it - even though it appears to be an obvious point.

I'm ok with using esc to close most popup windows in my app, but the main window should close using x or alt-f4 - I've used GUISetOnEvent($GUI_EVENT_CLOSE, "CloseWin") to do this.

However pressing esc closes it too - if I disable this (with a simple return in the CloseWin function), then the x and alt-f4 get disabled too.

Is there any way of distinguishing which of the three has been pressed/selected in the CloseWin function - so I exit when it is anything other than Esc?

Link to comment
Share on other sites

  • Moderators

delstone,

You can use Opt("GUICloseOnESC", 0) to prevent ESC closing your GUIs, but that is a script-wide block. :bye:

So you will have to come up with a way to use ESC to close your pop-ups. Fortunately you can use an Accelerator key like this: :doh:

#include <guiconstantsex.au3>
#include <windowsconstants.au3>

Opt("GUICloseOnESC", 0)

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Press me!", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            _Child()
    EndSwitch

WEnd

Func _Child()

    $hChild_GUI = GUICreate("Child", 300, 300, -1, -1, $WS_POPUP, Default, $hGUI)
    GUISetBkColor(0xFF0000)
    $cDummy = GUICtrlCreateDummy()
    GUISetState()

    Local $aAccelKeys[1][2] = [["{ESC}", $cDummy]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $hChild_GUI
                Switch $aMsg[0]
                    Case $cDummy
                        ExitLoop
                EndSwitch
        EndSwitch
    WEnd

    GUIDelete($hChild_GUI)

EndFunc

A suitable solution for you? :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23 nice example again ! :oops:

DelStone you can also simply set Hotkeys.

#include <GUIConstantsEx.au3>

Opt("GUICloseOnESC", 0)
HotKeySet ( "!{F4}", '_CloseMainWin' ) ; Alt F4
HotKeySet ( "{ESC}", "_CloseChildWin" )

Global $hGUI, $hChild_GUI
$hGUI = GUICreate("Test", 500, 500)
$cButton = GUICtrlCreateButton("Press me!", 10, 10, 80, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _CloseMainWin ( )
        Case $cButton
            _Child()
    EndSwitch
WEnd

Func _Child()
    $hChild_GUI = GUICreate("Child", 300, 300, -1, -1, -1, Default, $hGUI)
    GUISetBkColor(0xFF0000)
    GUISetState()
    While WinExists ( $hChild_GUI )
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    _CloseChildWin ( )
EndFunc

Func _CloseMainWin ( )
    GUIDelete($hGUI)
    Exit
EndFunc

Func _CloseChildWin ( )
    If $hChild_GUI Then GUIDelete($hChild_GUI)
EndFunc

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • Moderators

wakillon,

you can also simply set Hotkeys

But remember that HotKeys are set system-wide and so will fire even when those particular GUIs are not active. And they may not be settable at all if another app has already taken those combinations for itself. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

wakillon,

But remember that HotKeys are set system-wide and so will fire even when those particular GUIs are not active. And they may not be settable at all if another app has already taken those combinations for itself. :oops:

M23

A WinActive condition can be added but OP didn't precise what he want,

and your solution need child gui is active...

If you use the same solution for the Main Gui ( Alt+F4) when child Gui is show, you can't close both... :bye:

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Melba - excellent solution - simple and straightforward and works a treat! I should have posted this earlier - would have saved a number of hours of headbanging - thank you v much! :-)

I had thought about the hotkeys approach Wakillon, but it's a pain to exclude/include all the relevant windows, as I have already had to do it for ctrl-pgup/pgdn for moving through tabs and didn't relish having to use that approach again - Melba's solution is exactly what was needed.

Link to comment
Share on other sites

  • Moderators

wakillon,

If you use the same solution for the Main Gui ( Alt+F4) when child Gui is show, you can't close both

You can use Alt-F4 to exit the script when the child is active if you add another Accelerator key like this: :oops:

#include <guiconstantsex.au3>
#include <windowsconstants.au3>

Opt("GUICloseOnESC", 0)

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Press me!", 10, 10, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            _Child()
    EndSwitch

WEnd

Func _Child()

    $hChild_GUI = GUICreate("Child", 300, 300, -1, -1, $WS_POPUP, Default, $hGUI)
    GUISetBkColor(0xFF0000)
    $cDummy_1 = GUICtrlCreateDummy()
    $cDummy_2 = GUICtrlCreateDummy()
    GUISetState()

    Local $aAccelKeys[2][2] = [["{ESC}", $cDummy_1], ["!{F4}", $cDummy_2]]
    GUISetAccelerators($aAccelKeys)

    While 1
        $aMsg = GUIGetMsg(1)
        Switch $aMsg[1]
            Case $hChild_GUI
                Switch $aMsg[0]
                    Case $cDummy_1
                        ExitLoop
                    Case $cDummy_2
                        Exit
                EndSwitch
        EndSwitch
    WEnd

    GUIDelete($hChild_GUI)

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

DelStone,

In which case you need the first of my scripts in post #2. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

wakillon,

You can use Alt-F4 to exit the script when the child is active if you add another Accelerator key like this: ;)

M23

But in this case Alt+F4 doesn't work if there is no child window ! :doh:

However I must say I love your scite hopper program! Having nearly 15000 lines of code, it's an absolute boon to be able to jum directly to the required function - most of which I can't remember the names of any more !

Thanks a lot ! :oops:

Is it the last version ?

Forgot to mention, horizontally and vertically are with 2 l's and not one (as per the spelling in the hopper options)

Sorry for that, will be corrected in the next version ! :bye:

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • Moderators

wakillon,

But in this case Alt+F4 doesn't work if there is no child window !

Have you tried the script? Alt-F4 closes the main GUI just fine for me whether the child is active or not. :bye:

The Accelerator keys are only set for the last created GUI (unless you use the winhandle parameter) and so are not set when the child is closed - hence Alt-F4 works as normal for the main GUI. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

wakillon,

Have you tried the script? Alt-F4 closes the main GUI just fine for me whether the child is active or not. :doh:

The Accelerator keys are only set for the last created GUI (unless you use the winhandle parameter) and so are not set when the child is closed - hence Alt-F4 works as normal for the main GUI. :oops:

M23

Are you sure ? Try with Alt+F3 :bye:

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Thanks a lot ! :oops:

Is it the last version ?

It's v 1.0.2.1 - looks like the latest version

Aside from the minor spelling, there is one minor bug I've noticed - when you run "Includes Helper", it comments out "unused includes" - however I've found that a number of functions and constant in include files I use (my own include files to break the project down a little) are commented out - does your code check any include files that need the standard include files or does it just go by the main program and functions/variables used in that? It would be nice to trim down the includes I've done if possible as I think 30 odd includes may have some that I don't really need...

Link to comment
Share on other sites

  • Moderators

wakillon,

You are correct - you do need the winhandle parameter set. The Help file says "default is the previously used window", not "last created". Sorry. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It's v 1.0.2.1 - looks like the latest version

Aside from the minor spelling, there is one minor bug I've noticed - when you run "Includes Helper", it comments out "unused includes" - however I've found that a number of functions and constant in include files I use (my own include files to break the project down a little) are commented out - does your code check any include files that need the standard include files or does it just go by the main program and functions/variables used in that? It would be nice to trim down the includes I've done if possible as I think 30 odd includes may have some that I don't really need...

Well part was created by asdf8 so you should ask on his Topic.

I just found handy to associate two usefull utilities in one ! :oops:

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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