Jump to content

Problem with closing program


a2z
 Share

Recommended Posts

Hi. I have a small problem. I'm writing a small script, that monitors a mailbox of rate.ee
It's all ok, when i just start script, but if it connects to the server and starts monitoring, then it's not possible to quit with $GUI_EVENT_CLOSE or ExitLoop function.
Where the problem is?

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


Global $oIE, $msg, $new_message
;Opt("TrayMenuMode", 1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.
If Not FileExists("settings.ini") Then
    IniWrite("settings.ini", "Login info", "save", "True")
EndIf
;elements and variables
$Form1 = GUICreate("Mail notifier v 0.1", 245, 185, -1, -1)
$settingsitem = TrayCreateItem("Seadista")
GUICtrlSetState(-1, $GUI_DISABLE)
TrayCreateItem("")
$aboutitem = TrayCreateItem("Info")
TrayCreateItem("")
$exititem = TrayCreateItem("Vдlju")
TraySetState()
$msg = GUIGetMsg()
$get_user = IniRead("settings.ini", "Login info", "user", "")
$get_pass = IniRead("settings.ini", "Login info", "pass", "")
$save = IniRead("settings.ini", "Login info", "save", "")
$remember = GUICtrlCreateCheckbox("maleta mind", 8, 88, 97, 17)
If $save = "True" Then
    GUICtrlSetState(-1, $GUI_CHECKED)
Else
    GUICtrlSetState(-1, $GUI_UNCHECKED)
EndIf
If GUICtrlRead($remember) = $GUI_CHECKED Then
    $user = GUICtrlCreateInput($get_user, 96, 8, 121, 24, -1, $WS_EX_CLIENTEDGE)             ;user
    $pass = GUICtrlCreateInput($get_pass, 96, 40, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)  ;pass
Else
    $user = GUICtrlCreateInput("", 96, 8, 121, 24, -1, $WS_EX_CLIENTEDGE)             ;user
    $pass = GUICtrlCreateInput("", 96, 40, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)  ;pass
EndIf
GUICtrlCreateLabel("Kasutajanimi", 8, 16, 80, 20)
GUICtrlCreateLabel("Parool", 8, 48, 44, 20)
$go = GUICtrlCreateButton("sisene", 136, 80, 75, 25)
$start = GUICtrlCreateButton("alusta", 8, 120, 203, 25)
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateLabel("By ...", 8, 160, 146, 20)
GUISetState(@SW_SHOW)
While 1
    $tray_msg = TrayGetMsg()
    $msg = GUIGetMsg()
    Select
        Case $msg = $go
            
            If GUICtrlRead($remember) = $GUI_CHECKED Then ; If Checkbox is selected & pess ok
                IniWrite("settings.ini", "Login info", "user", GUICtrlRead($user))
                IniWrite("settings.ini", "Login info", "pass", GUICtrlRead($pass))
                IniWrite("settings.ini", "Login info", "Save", "True")
            Else
                IniWrite("settings.ini", "Login info", "save", "FALSE")
                IniDelete("settings.ini", "Login info", "user")
                IniDelete("settings.ini", "Login info", "pass")
            EndIf
            
            ;;;;;;;;;;;;;;;;;;;;;;
            If @error Or Not GUICtrlRead($user) Or Not GUICtrlRead($pass) Then
                MsgBox(0, "VIGA", "Дkki alustuseks kirjutaks ikka andmed ka?")
                Exit
                
            EndIf
            ;creat splash screen window
            $message = "Ьhendamine..."
            SplashTextOn("RateMail", $message, 200, 40)
            ;end of splash screen
            
            $oIE = _IECreate ("www.rate.ee/", 0, 1)
            _IELoadWait ($oIE)
            Sleep(200)
            $o_form = _IEFormGetObjByName ($oIE, "loginform")
            Sleep(200)
            $o_user = _IEFormElementGetObjByName ($o_form, "username")
            Sleep(200)
            $o_password = _IEFormElementGetObjByName ($o_form, "password")
            Sleep(200)
            
            While 1
                If @error = 0 Then
                    ExitLoop
                Else
                    _IENavigate ($oIE, "http://www.rate.ee/login.php")
                    _IELoadWait ($oIE)
                EndIf
                
            WEnd
            
            _IEFormElementSetValue ($o_user, GUICtrlRead($user))
            Sleep(100)
            _IEFormElementSetValue ($o_password, GUICtrlRead($pass))
            Sleep(100)
            _IEFormSubmit ($o_form)
            _IELoadWait ($oIE)
            ;Checking if page was loaded sucessfully after login, if not, then Refresh page until it Sucessfuly loads
            SplashOff()
            $oBOdy = _IEBodyReadText ($oIE)
            If StringInStr($oBOdy, "Proovi uuesti!") Then
                MsgBox(0, "VIGA", "Rate.ee ьtleb: Sellise nime ja parooliga kasutaja meil puudub. Proovi uuesti!")
            EndIf
            If StringInStr($oBOdy, "Koodi") Then
                MsgBox(0, "VIGA", "Rate.ee ьtleb: Konto on blokeeritud viieks minutiks, kuna sisestasid parooli 3 korda valesti.")
                
                _IENavigate ($oIE, "http://www.rate.ee/")
                _IELoadWait ($oIE)
                If @error <> 0 Then
                    MsgBox(0, "VIGA", "Ei saa sisse. Proovige mхne aja pдrast uuesti.")
                    Exit
                EndIf
            EndIf
            While 1
                $HTML = _IEBodyReadHTML ($oIE)
                $msgr = GUIGetMsg()
                $tray_msg = TrayGetMsg()
                _IENavigate ($oIE, "http://www.rate.ee/control.php");if found wordpeace wrong user
                _IELoadWait ($oIE)
                If StringInStr($HTML, "newletter.gif") Then
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "true")
                Else
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "false")
                EndIf
                $check_new_message = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage")
                If $check_new_message = "true" Then
                    TrayTip("RateMail", "Saabunud uued kirjad/teated", 5, 1)
                    Sleep(5000)
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Teile on saabunud uusi kirju ja/vхi teateid!")
                EndIf
                If $check_new_message = "false" Then
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Uusi kirju/teateid pole.")
                EndIf
                _IEAction ($oIE, "refresh")
                Sleep(5000)
                _IEAction ($oIE, "refresh")
                Select
                    Case $msgr = $GUI_EVENT_CLOSE
                        _IEQuit($oIE)
                        ExitLoop
                    Case $tray_msg = $exititem
                        _IEQuit($oIE)
                        ExitLoop
                    Case $tray_msg = $aboutitem
            MsgBox(64, "Programmist", "RateMail notifier" & @CRLF & "" & @CRLF & "Version: 0.1" & @CRLF & "Release date: December 2007" & @CRLF & "Author: Sergei I.")
                Case Else
                EndSelect
            WEnd
            Exit
            
        Case $msg = $GUI_EVENT_CLOSE
            
            ExitLoop
            Exit
        Case $tray_msg = 0
            ContinueLoop
        Case $tray_msg = $aboutitem
            MsgBox(64, "Programmist", "RateMail notifier" & @CRLF & "" & @CRLF & "Version: 0.1" & @CRLF & "Release date: December 2007" & @CRLF & "Author: Sergei")
        Case $tray_msg = $exititem
            ExitLoop
        Case Else
    EndSelect
WEnd
Exit
Edited by a2z
Link to comment
Share on other sites

You're right - with just a quick look, it appears that it should exit, but why bother with ExitLoop when you want to Exit?

Change

Case $msgr = $GUI_EVENT_CLOSE
                        _IEQuit($oIE)
                        ExitLoopoÝ÷ ÚÚºÚ"µÍBBBBPØÙH   ÌÍÛÙÜH ÌÍÑÕRWÑUSÐÓÔÑBBBBBBWÒQT]Z]
    ÌÍÛÒQJBBBBBBQ^]oÝ÷ Ù©Ýr§æ®¶­s`66Rb33c¶×6rÒb33c´uTôUdTåEô4Äõ4P WDÆö÷ WoÝ÷ ÚÚºÚ"µÍBPØÙH   ÌÍÛÙÈH ÌÍÑÕRWÑUSÐÓÔÑBBBQ^]
Link to comment
Share on other sites

I made all this changes, but no effect. It still refreshing page and doesn't stop application. I think that problem is somewere in:

While 1
                $HTML = _IEBodyReadHTML ($oIE)
                $msgr = GUIGetMsg()
                $tray_msg = TrayGetMsg()
                _IENavigate ($oIE, "http://www.rate.ee/control.php");if found wordpeace wrong user
                _IELoadWait ($oIE)
                If StringInStr($HTML, "newletter.gif") Then
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "true")
                Else
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "false")
                EndIf
                $check_new_message = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage")
                If $check_new_message = "true" Then
                    TrayTip("RateMail", "Saabunud uued kirjad/teated", 5, 1)
                    Sleep(5000)
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Teile on saabunud uusi kirju ja/vхi teateid!")
                EndIf
                If $check_new_message = "false" Then
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Uusi kirju/teateid pole.")
                EndIf
                _IEAction ($oIE, "refresh")
                Sleep(5000)
                _IEAction ($oIE, "refresh")
                Select
                    Case $msgr = $GUI_EVENT_CLOSE
                        _IEQuit($oIE)
                        Exit
                    Case $tray_msg = $exititem
                        _IEQuit($oIE)
                        ExitLoop
                    Case $tray_msg = $aboutitem
            MsgBox(64, "Programmist", "RateMail notifier" & @CRLF & "" & @CRLF & "Version: 0.1" & @CRLF & "Release date: December 2007" & @CRLF & "Author: Sergei I.")
                Case Else
                EndSelect
            WEndoÝ÷ Øjë­ê^(ç$xÚÞ~·¬)ànë^Æ+_ºw-ìj·§¢×§i¹^u8b²«¶Ü¡×¡ë'ßÛp¢¹-¡«­¢+Ù
ÍÀÌØíÑÉå}µÍôÀÌØí½ÕѥѴ(5Í ½à ØаÅÕ½ÐíAɽɵµ¥ÍÐÅÕ½Ðì°ÅÕ½ÐíIÑ5¥°¹½Ñ¥¥ÈÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐíYÉÍ¥½¸èÀ¸ÄÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐíI±ÍÑèµÈÈÀÀÜÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐíÕÑ¡½ÈèMɤ%Ù¹¥Í¹­¼ÅÕ½Ðì¤
Edited by a2z
Link to comment
Share on other sites

Putting a bunch of other activity into a GuiGetMsg() loop makes it unreliable. Things like _IENavigate() and _IELoadWait() have no place in a GuiGetMsg() loop because they make it so slow.

This script cries out for GuiOnEventMode, so the other activity can continue, but GUI events will interrupt and be handled immediately.

:)

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

i added Opt("GUIOnEventMode", 1) option

So now script doesn't connect to the server and it's not possible to quit with the system exit button (only with tray button).

Maybe you could configure this script by yourself, because i have no idea how can i fix it.

Link to comment
Share on other sites

Please take a look at these functions. You need to completely re-write the way your script handles the GUI. Changing the option (Opt("GUIOnEventMode", 1)) at the top of the script without re-writing the way the internal workings of the script function will result in a dead script.

http://www.autoitscript.com/autoit3/docs/g...OnEventMode.htm

http://www.autoitscript.com/autoit3/docs/f...lSetOnEvent.htm

http://www.autoitscript.com/autoit3/docs/f...ISetOnEvent.htm

From the help file:

OnEvent functions are only called when the option GUIOnEventMode is set to 1 - when in this mode GUIGetMsg is NOT used at all.

Please look at the examples from those links I gave you. It shows you exactly how the GUIOnEventMode handles GUI interrupts.


Also, I whipped this up. I have no idea if it will work because I dare not run this on my system with all the stuff that it is doing.
 

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


Global $oIE, $msg, $new_message
;Opt("TrayMenuMode", 1)   ; Default tray menu items (Script Paused/Exit) will not be shown
Opt("WinTitleMatchMode", 2) ; use any part of the window name
Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.
If Not FileExists("settings.ini") Then
    IniWrite("settings.ini", "Login info", "save", "True")
EndIf
;elements and variables
$Form1 = GUICreate("Mail notifier v 0.1", 245, 185, -1, -1)
$settingsitem = TrayCreateItem("Seadista")
GUICtrlSetState(-1, $GUI_DISABLE)
TrayCreateItem("")
$aboutitem = TrayCreateItem("Info")
TrayCreateItem("")
$exititem = TrayCreateItem("V?lju")
TraySetState()
$msg = GUIGetMsg()
$get_user = IniRead("settings.ini", "Login info", "user", "")
$get_pass = IniRead("settings.ini", "Login info", "pass", "")
$save = IniRead("settings.ini", "Login info", "save", "")
$remember = GUICtrlCreateCheckbox("maleta mind", 8, 88, 97, 17)
If $save = "True" Then
    GUICtrlSetState(-1, $GUI_CHECKED)
Else
    GUICtrlSetState(-1, $GUI_UNCHECKED)
EndIf
If GUICtrlRead($remember) = $GUI_CHECKED Then
    $user = GUICtrlCreateInput($get_user, 96, 8, 121, 24, -1, $WS_EX_CLIENTEDGE)             ;user
    $pass = GUICtrlCreateInput($get_pass, 96, 40, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)  ;pass
Else
    $user = GUICtrlCreateInput("", 96, 8, 121, 24, -1, $WS_EX_CLIENTEDGE)             ;user
    $pass = GUICtrlCreateInput("", 96, 40, 121, 24, $ES_PASSWORD, $WS_EX_CLIENTEDGE)  ;pass
EndIf
GUICtrlCreateLabel("Kasutajanimi", 8, 16, 80, 20)
GUICtrlCreateLabel("Parool", 8, 48, 44, 20)
$go = GUICtrlCreateButton("sisene", 136, 80, 75, 25)
$start = GUICtrlCreateButton("alusta", 8, 120, 203, 25)
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlCreateLabel("By ...", 8, 160, 146, 20)
GUISetState(@SW_SHOW)
While 1
    $tray_msg = TrayGetMsg()
    $msg = GUIGetMsg()
    Select
        Case $msg = $go
           Opt("GUISetOnEventMode",1)
           GUISetOnEvent($GUI_EVENT_CLOSE, "EventClose",$Form1)
            If GUICtrlRead($remember) = $GUI_CHECKED Then ; If Checkbox is selected & pess ok
                IniWrite("settings.ini", "Login info", "user", GUICtrlRead($user))
                IniWrite("settings.ini", "Login info", "pass", GUICtrlRead($pass))
                IniWrite("settings.ini", "Login info", "Save", "True")
            Else
                IniWrite("settings.ini", "Login info", "save", "FALSE")
                IniDelete("settings.ini", "Login info", "user")
                IniDelete("settings.ini", "Login info", "pass")
            EndIf
           
            ;;;;;;;;;;;;;;;;;;;;;;
            If @error Or Not GUICtrlRead($user) Or Not GUICtrlRead($pass) Then
                MsgBox(0, "VIGA", "?kki alustuseks kirjutaks ikka andmed ka?")
                Exit
               
            EndIf
            ;creat splash screen window
            $message = "?hendamine..."
            SplashTextOn("RateMail", $message, 200, 40)
            ;end of splash screen
           
            $oIE = _IECreate ("www.rate.ee/", 0, 1)
            _IELoadWait ($oIE)
            Sleep(200)
            $o_form = _IEFormGetObjByName ($oIE, "loginform")
            Sleep(200)
            $o_user = _IEFormElementGetObjByName ($o_form, "username")
            Sleep(200)
            $o_password = _IEFormElementGetObjByName ($o_form, "password")
            Sleep(200)
           
            While 1
                If @error = 0 Then
                    ExitLoop
                Else
                    _IENavigate ($oIE, "http://www.rate.ee/login.php")
                    _IELoadWait ($oIE)
                EndIf
               
            WEnd
           
            _IEFormElementSetValue ($o_user, GUICtrlRead($user))
            Sleep(100)
            _IEFormElementSetValue ($o_password, GUICtrlRead($pass))
            Sleep(100)
            _IEFormSubmit ($o_form)
            _IELoadWait ($oIE)
            ;Checking if page was loaded sucessfully after login, if not, then Refresh page until it Sucessfuly loads
            SplashOff()
            $oBOdy = _IEBodyReadText ($oIE)
            If StringInStr($oBOdy, "Proovi uuesti!") Then
                MsgBox(0, "VIGA", "Rate.ee ?tleb: Sellise nime ja parooliga kasutaja meil puudub. Proovi uuesti!")
            EndIf
            If StringInStr($oBOdy, "Koodi") Then
                MsgBox(0, "VIGA", "Rate.ee ?tleb: Konto on blokeeritud viieks minutiks, kuna sisestasid parooli 3 korda valesti.")
               
                _IENavigate ($oIE, "http://www.rate.ee/")
                _IELoadWait ($oIE)
                If @error <> 0 Then
                    MsgBox(0, "VIGA", "Ei saa sisse. Proovige m?ne aja p?rast uuesti.")
                    Exit
                EndIf
            EndIf
            While 1
                $HTML = _IEBodyReadHTML ($oIE)
                $msgr = GUIGetMsg()
                $tray_msg = TrayGetMsg()
                _IENavigate ($oIE, "http://www.rate.ee/control.php");if found wordpeace wrong user
                _IELoadWait ($oIE)
                If StringInStr($HTML, "newletter.gif") Then
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "true")
                Else
                    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage", "REG_SZ", "false")
                EndIf
                $check_new_message = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\RateMail", "newmessage")
                If $check_new_message = "true" Then
                    TrayTip("RateMail", "Saabunud uued kirjad/teated", 5, 1)
                    Sleep(5000)
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Teile on saabunud uusi kirju ja/v?i teateid!")
                EndIf
                If $check_new_message = "false" Then
                    TraySetToolTip ("RateMail on aktiivne" & @LF & "Uusi kirju/teateid pole.")
                EndIf
                _IEAction ($oIE, "refresh")
                Sleep(5000)
                _IEAction ($oIE, "refresh")
                Select
                    Case $msgr = $GUI_EVENT_CLOSE
                        _IEQuit($oIE)
                        ExitLoop
                    Case $tray_msg = $exititem
                        _IEQuit($oIE)
                        ExitLoop
                    Case $tray_msg = $aboutitem
            MsgBox(64, "Programmist", "RateMail notifier" & @CRLF & "" & @CRLF & "Version: 0.1" & @CRLF & "Release date: December 2007" & @CRLF & "Author: Sergei I")
                Case Else
                EndSelect
            WEnd
            Exit
           
        Case $msg = $GUI_EVENT_CLOSE
           
            ExitLoop
            Exit
        Case $tray_msg = 0
            ContinueLoop
        Case $tray_msg = $aboutitem
            MsgBox(64, "Programmist", "RateMail notifier" & @CRLF & "" & @CRLF & "Version: 0.1" & @CRLF & "Release date: December 2007" & @CRLF & "Author: Sergei I")
        Case $tray_msg = $exititem
            ExitLoop
        Case Else
    EndSelect
WEnd
Exit

Func EventClose()
    Exit
EndFunc


I hope that helps. Also, I was going to have it turn off GUIOnEventMode when it was done, but I notice you have it exit the script. So, I guess there was no need.

- The Kandie Man ;-)

Edited by Jon

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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