Jump to content
Sign in to follow this  
cyanidemonkey

GUI not closing, why?

Recommended Posts

cyanidemonkey

Can anyone see why this GUI will not close when the red X is clicked?

The minimise and restore work ok.

#include <GUIConstants.au3>
#include <IE.au3>
HotKeySet("{ESC}", "Terminate")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUICreate("TRANSPOWER - Induction, Stage 1 Welcome.",899, 674)

Opt("ExpandVarStrings", 1)
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 900,675)
$oIE.navigate("@ScriptDir@\test.html")
$oIE.document.body.scroll = "no"
$oIE = 0
GUISetState()

While 1
  Sleep(1000)
Wend

Func Terminate()
    Exit 0
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE 
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE 
    EndSelect
EndFunc

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites
SmOke_N

Well one, your using GUISetOnEvent() and you don't have: Opt('GUIOnEventMode', 1) and for 2.. you have case @GUI_CtrlId = $GUI_EVENT_CLOSE.. but you not telling it to exit if it's true:

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
    EndSelect
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
cyanidemonkey

updated code as below, but still will not close...

#include <GUIConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "Terminate")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUICreate("TRANSPOWER - Induction, Stage 1 Welcome.",899, 674)

Opt("ExpandVarStrings", 1)
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 900,675)
$oIE.navigate("@ScriptDir@\test.html")
$oIE.document.body.scroll = "no"
$oIE = 0
GUISetState()

While 1
  Sleep(1000)
Wend

Func Terminate()
    Exit 0
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    Exit 0
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE 
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE 
    EndSelect
EndFunc

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites
greenmachine

updated code as below, but still will not close...

#include <GUIConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "Terminate")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUICreate("TRANSPOWER - Induction, Stage 1 Welcome.",899, 674)

Opt("ExpandVarStrings", 1)
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 900,675)
$oIE.navigate("@ScriptDir@\test.html")
$oIE.document.body.scroll = "no"
$oIE = 0
GUISetState()

While 1
  Sleep(1000)
Wend

Func Terminate()
    Exit 0
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
    Exit 0
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE 
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE 
    EndSelect
EndFunc
Minimize and restore will work regardless of whether you have the GUI events for them or not. Your problem is that you declare the events before you declare the GUI window the event is triggered from. Change it to this and you'll be fine:

#include <GUIConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "Terminate")

$GUIWindow = GUICreate("TRANSPOWER - Induction, Stage 1 Welcome.",899, 674)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

Opt("ExpandVarStrings", 1)
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 900,675)
$oIE.navigate("@ScriptDir@\test.html")
$oIE.document.body.scroll = "no"
$oIE = 0
GUISetState()

While 1
  Sleep(1000)
Wend

Func Terminate()
    Exit 0
EndFunc

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
        Exit 0
    EndSelect
EndFunc

Now, whenever you declare a GUI event, it must go AFTER the window or control that goes with the event.

Share this post


Link to post
Share on other sites
eJan

Try with few lines less

#include <GUIConstants.au3>
#include <IE.au3>

HotKeySet("{ESC}", "Terminate")

GUICreate("TRANSPOWER - Induction, Stage 1 Welcome.",899, 674)

Opt("ExpandVarStrings", 1)
$oIE = ObjCreate("Shell.Explorer.2")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 900,675)
$oIE.navigate("@ScriptDir@\test.html")
$oIE.document.body.scroll = "no"
$oIE = 0
GUISetState()

Func Terminate()
    Exit 0
EndFunc

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
Wend

Share this post


Link to post
Share on other sites
cyanidemonkey

ahhhh, thanks eJan

BTW - your avatar - Kraftwerks' AutoBahn, cool album. :lmao:

Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.