Jump to content

$GUI_EVENT_CLOSE wont close while functions running


dcop
 Share

Recommended Posts

While this is running the the GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") and the Exit button wont terminate the GUI. I haven't had this issue with other scripts while they're running. Anything obvious stand out?

TIA, Dennis

#include "GUIConstants.au3"
FileDelete("C:\winnt\bfile.txt")
FileDelete("C:\winnt\list.txt")
If WinExists("Accessory Manager - [QA USERCODE ON MKEV01]") Then 
else 
    MsgBox(0,"","Sorry, QA Session Must Be Running")
    Exit
EndIf
$passwd = InputBox("Doh!", "Enter Password And It's Duff Time", "", "*")
$sendcap = 1
If $passwd = "1"  Then go()
if @error  Then Exit
go()
Func go()
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
$Form1 = GUICreate("B Mod", 325, 513, 192, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetBkColor(0x00FFFF)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 193, 512, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("", 216, 168, 73, 49, $BS_ICON)
GUICtrlSetOnEvent(-1, "DoMod")
GUICtrlSetImage($Button1, "C:\winnt\Homer.ico")
$Button2 = GUICtrlCreateButton("Import", 216, 268, 73, 49)
GUICtrlSetOnEvent(-1, "import")
$Button2 = GUICtrlCreateButton("EXIT", 216, 368, 73, 49)
GUICtrlSetOnEvent(-1, "CLOSEClicked")
$prg1 = GUICtrlCreateLabel("", 200, 68, 120, 10)
GUICtrlSetBkColor(-1, 0x00FFFF)
GUISetState(@SW_SHOW)

    While 1
     Sleep(100)
     WinMove ("B Mod", "", 1025, 0 , 250, 772)
     WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
     GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
    WEnd
EndFunc

Func DoMod()
;~ run("C:\winnt\prgss.exe", "", @SW_MAXIMIZE)
$sum = 1
$one = ControlCommand("B Mod", "", "Edit1", "GetLine", $sum)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
$line = $one
Sleep(1000)
ClipPut($line)
Sleep(1000)
send("/CAP-MOD,SENT,")
Send(ClipGet())
Sleep(1000)
send("{NUMPADADD}")
$count = 1
$psum = 1
Do
    $pnext = $psum + "1"
    $pline = ControlCommand("B Mod", "", "Edit1", "GetLine", $pnext)
    $psum = $psum + 1
    $ptot = $psum - "1"
Until $pline = 1
Sleep(200)
    While 1
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Sleep(500)
    $next = $sum + "1"
    $sum = $next
    $line = ControlCommand("B Mod", "", "Edit1", "GetLine", $next)
    If $line = 1 Then   
        SplashImageOn ( "Let's Eat Boy's", "c:\winnt\chief.gif",300)
        Sleep(4000)
    Else
    EndIf
    If $line = 1 Then WinClose("B Mod")
    If $line = 1 Then Exit
    ClipPut($line)
    Sleep(1000)
    send("/CAP-MOD,SENT,")
    Send(ClipGet())
    Sleep(1000)
    send("{NUMPADADD}")
    Sleep(100)
$count = $count + 1
GUICtrlSetData ( 7, $count & " of " & $ptot)    
    Wend
EndFunc

Func CLOSEClicked()
Exit
EndFunc

func import()
If $sendcap = 1 Then
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Sleep(200)
    Send("/CAP-VIEW,B")
    Sleep(200)
    Send("{NUMPADADD}")
Else
EndIf
$sendcap = $sendcap + 1
WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
Sleep(100)
Send("{ALT}")
Sleep(200)
Send("E")
Sleep(200)
Send("T")
Sleep(200)
send("^{INS}")
Sleep(100)
$list = ClipGet()
FileOpen("c:\winnt\list.txt", 2)
Sleep(500)
FileWrite ("c:\winnt\list.txt", $list)
FileOpen("c:\winnt\bfile.txt", 1)
$fil = FileRead("c:\winnt\list.txt", 100000)
$occur = 1
$searchb = 1
    While $searchb <> 0
    $searchb = StringInStr ( $fil, "b", 0, $occur)
    $par = StringMid ( $fil, $searchb, 6)
    $occur = $occur + 1
    $par2 = StringTrimLeft ( $par, 1 )
    $chkdig = StringIsDigit ( $par2)
    If $chkdig = 1 then FileWrite ("c:\winnt\bfile.txt", "B"&$par2&@CRLF)
    WEnd
$theBs = FileRead("c:\winnt\bfile.txt", 3000)
ClipPut($theBs)
$putBs = ClipGet()
GUICtrlSetData (3, $putBs)
Sleep(200)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
Send("{NUMPADADD}")
EndFunc
Link to comment
Share on other sites

try stripping the function tags from Go().... like just let the script run the Go() function like so

#include "GUIConstants.au3"
FileDelete("C:\winnt\bfile.txt")
FileDelete("C:\winnt\list.txt")
If WinExists("Accessory Manager - [QA USERCODE ON MKEV01]") Then
Else
    MsgBox(0, "", "Sorry, QA Session Must Be Running")
    Exit
EndIf
$passwd = InputBox("Doh!", "Enter Password And It's Duff Time", "", "*")
$sendcap = 1
If $passwd = "1" Then
        $msg = GUIGetMsg()
        ; == GUI generated with Koda ==
        Opt("GUIOnEventMode", 1)
        Opt("GUICloseOnESC", 0)
        $Form1 = GUICreate("B Mod", 325, 513, 192, 125)
        GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
        GUISetBkColor(0x00FFFF)
        $Edit1 = GUICtrlCreateEdit("", 0, 0, 193, 512, -1, $WS_EX_CLIENTEDGE)
        $Button1 = GUICtrlCreateButton("", 216, 168, 73, 49, $BS_ICON)
        GUICtrlSetOnEvent(-1, "DoMod")
        GUICtrlSetImage($Button1, "C:\winnt\Homer.ico")
        $Button2 = GUICtrlCreateButton("Import", 216, 268, 73, 49)
        GUICtrlSetOnEvent(-1, "import")
        $Button2 = GUICtrlCreateButton("EXIT", 216, 368, 73, 49)
        GUICtrlSetOnEvent(-1, "CLOSEClicked")
        $prg1 = GUICtrlCreateLabel("", 200, 68, 120, 10)
        GUICtrlSetBkColor(-1, 0x00FFFF)
        GUISetState(@SW_SHOW)
        
Do
        While 1
            Sleep(100)
            WinMove("B Mod", "", 1025, 0, 250, 772)
            WinMove("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
            GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
        WEnd
    Until $msg = $GUI_EVENT_CLOSE
ElseIf @error Then Exit
EndIf

Func DoMod()
;~ run("C:\winnt\prgss.exe", "", @SW_MAXIMIZE)
    $sum = 1
    $one = ControlCommand("B Mod", "", "Edit1", "GetLine", $sum)
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    WinMove("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
    $line = $one
    Sleep(1000)
    ClipPut($line)
    Sleep(1000)
    Send("/CAP-MOD,SENT,")
    Send(ClipGet())
    Sleep(1000)
    Send("{NUMPADADD}")
    $count = 1
    $psum = 1
    Do
        $pnext = $psum + "1"
        $pline = ControlCommand("B Mod", "", "Edit1", "GetLine", $pnext)
        $psum = $psum + 1
        $ptot = $psum - "1"
    Until $pline = 1
    Sleep(200)
    While 1
        WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
        Sleep(500)
        $next = $sum + "1"
        $sum = $next
        $line = ControlCommand("B Mod", "", "Edit1", "GetLine", $next)
        If $line = 1 Then
            SplashImageOn("Let's Eat Boy's", "c:\winnt\chief.gif", 300)
            Sleep(4000)
        Else
        EndIf
        If $line = 1 Then WinClose("B Mod")
        If $line = 1 Then Exit
        ClipPut($line)
        Sleep(1000)
        Send("/CAP-MOD,SENT,")
        Send(ClipGet())
        Sleep(1000)
        Send("{NUMPADADD}")
        Sleep(100)
        $count = $count + 1
        GUICtrlSetData(7, $count & " of " & $ptot)
    WEnd
EndFunc

Func CLOSEClicked()
    Exit
EndFunc

Func import()
    If $sendcap = 1 Then
        WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
        Sleep(200)
        Send("/CAP-VIEW,B")
        Sleep(200)
        Send("{NUMPADADD}")
    Else
    EndIf
    $sendcap = $sendcap + 1
    WinMove("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Sleep(100)
    Send("{ALT}")
    Sleep(200)
    Send("E")
    Sleep(200)
    Send("T")
    Sleep(200)
    Send("^{INS}")
    Sleep(100)
    $list = ClipGet()
    FileOpen("c:\winnt\list.txt", 2)
    Sleep(500)
    FileWrite("c:\winnt\list.txt", $list)
    FileOpen("c:\winnt\bfile.txt", 1)
    $fil = FileRead("c:\winnt\list.txt", 100000)
    $occur = 1
    $searchb = 1
    While $searchb <> 0
        $searchb = StringInStr($fil, "b", 0, $occur)
        $par = StringMid($fil, $searchb, 6)
        $occur = $occur + 1
        $par2 = StringTrimLeft($par, 1)
        $chkdig = StringIsDigit($par2)
        If $chkdig = 1 Then FileWrite("c:\winnt\bfile.txt", "B" & $par2 & @CRLF)
    WEnd
    $theBs = FileRead("c:\winnt\bfile.txt", 3000)
    ClipPut($theBs)
    $putBs = ClipGet()
    GUICtrlSetData(3, $putBs)
    Sleep(200)
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Send("{NUMPADADD}")
EndFunc

dunno if it will work or not though :) tells me Sorry QA ....... since i don't have it running :(

Edited by 4gotn1
Link to comment
Share on other sites

Still no luck. I removed the func tags for go() and removed the close statement form the While. I commented out some stuff so u can try it. put about 10 lines of text in the edit box and hit the homer button then try to close while running. Thanx....Dennis

#include "GUIConstants.au3"
FileDelete("C:\winnt\bfile.txt")
FileDelete("C:\winnt\list.txt")
;~ If WinExists("Accessory Manager - [QA USERCODE ON MKEV01]") Then 
;~ else 
;~  MsgBox(0,"","Sorry, QA Session Must Be Running")
;~  Exit
;~ EndIf
$passwd = InputBox("Doh!", "Enter Password And It's Duff Time", "", "*")
$sendcap = 1
If $passwd = "1"  Then;go()
Else
    Exit
EndIf
If @error  Then Exit
;~ go()
;~ Func go()
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
$Form1 = GUICreate("B Mod", 325, 513, 192, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetBkColor(0x00FFFF)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 193, 512, -1, $WS_EX_CLIENTEDGE)
$Button1 = GUICtrlCreateButton("", 216, 168, 73, 49, $BS_ICON)
GUICtrlSetOnEvent(-1, "DoMod")
GUICtrlSetImage($Button1, "C:\winnt\Homer.ico")
$Button2 = GUICtrlCreateButton("Import", 216, 268, 73, 49)
GUICtrlSetOnEvent(-1, "import")
$Button2 = GUICtrlCreateButton("EXIT", 216, 368, 73, 49)
GUICtrlSetOnEvent(-1, "CLOSEClicked")
$prg1 = GUICtrlCreateLabel("", 200, 68, 120, 10)
GUICtrlSetBkColor(-1, 0x00FFFF)
GUISetState(@SW_SHOW)

    While 1
     Sleep(100)
     WinMove ("B Mod", "", 1025, 0 , 250, 772)
     WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
     WEnd
;~ EndFunc

Func DoMod()
;~ run("C:\winnt\prgss.exe", "", @SW_MAXIMIZE)
$sum = 1
$one = ControlCommand("B Mod", "", "Edit1", "GetLine", $sum)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
$line = $one
Sleep(1000)
ClipPut($line)
Sleep(1000)
send("/CAP-MOD,SENT,")
Send(ClipGet())
Sleep(1000)
send("{NUMPADADD}")
$count = 1
$psum = 1
Do
    $pnext = $psum + "1"
    $pline = ControlCommand("B Mod", "", "Edit1", "GetLine", $pnext)
    $psum = $psum + 1
    $ptot = $psum - "1"
Until $pline = 1
Sleep(200)
    While 1
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Sleep(500)
    $next = $sum + "1"
    $sum = $next
    $line = ControlCommand("B Mod", "", "Edit1", "GetLine", $next)
    If $line = 1 Then   
        SplashImageOn ( "Let's Eat Boy's", "c:\winnt\chief.gif",300)
        Sleep(4000)
    Else
    EndIf
    If $line = 1 Then WinClose("B Mod")
    If $line = 1 Then Exit
    ClipPut($line)
    Sleep(1000)
    send("/CAP-MOD,SENT,")
    Send(ClipGet())
    Sleep(1000)
    send("{NUMPADADD}")
    Sleep(100)
$count = $count + 1
GUICtrlSetData ( 7, $count & " of " & $ptot)    
    Wend
EndFunc

Func CLOSEClicked()
Exit
EndFunc

func import()
If $sendcap = 1 Then
    WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
    Sleep(200)
    Send("/CAP-VIEW,B")
    Sleep(200)
    Send("{NUMPADADD}")
Else
EndIf
$sendcap = $sendcap + 1
WinMove ("Accessory Manager - [QA USERCODE ON MKEV01]", "", 0, 1, 1026, 772)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
Sleep(100)
Send("{ALT}")
Sleep(200)
Send("E")
Sleep(200)
Send("T")
Sleep(200)
send("^{INS}")
Sleep(100)
$list = ClipGet()
FileOpen("c:\winnt\list.txt", 2)
Sleep(500)
FileWrite ("c:\winnt\list.txt", $list)
FileOpen("c:\winnt\bfile.txt", 1)
$fil = FileRead("c:\winnt\list.txt", 100000)
$occur = 1
$searchb = 1
    While $searchb <> 0
    $searchb = StringInStr ( $fil, "b", 0, $occur)
    $par = StringMid ( $fil, $searchb, 6)
    $occur = $occur + 1
    $par2 = StringTrimLeft ( $par, 1 )
    $chkdig = StringIsDigit ( $par2)
    If $chkdig = 1 then FileWrite ("c:\winnt\bfile.txt", "B"&$par2&@CRLF)
    WEnd
$theBs = FileRead("c:\winnt\bfile.txt", 3000)
ClipPut($theBs)
$putBs = ClipGet()
GUICtrlSetData (3, $putBs)
Sleep(200)
WinActivate("Accessory Manager - [QA USERCODE ON MKEV01]", "")
Send("{NUMPADADD}")
EndFunc
Link to comment
Share on other sites

Man, i dont get it. Even the Opt("GUICloseOnESC", 1) wont close it down when ESC is hit while domod() running. Somewhow this function is making all events uresponsive othet the the Windows minimize (-).

Link to comment
Share on other sites

I've tried both modes, onevent and messageloop and the only way I've been able to stop it is thru the tray icon. I dont get it.

as a last resort you could put in domod():

If   $msg = $GUI_EVENT_CLOSE   Then
      Exit
EndIf

but yeah that is wierd =S

Link to comment
Share on other sites

Maybe I'm expecting something that can't happen with AutoIT but being new could someone please verify. With this running and the Test Function button hit isn't there a way to Exit the script with the windows 'x' or my UDF thru my Exit button while the Func test() is running? .....Dennis

#include <GUIConstants.au3>
; == GUI generated with Koda ==
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
$Form1 = GUICreate("Test", 433, 200, 192, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("Exit", 112, 40, 97, 49)
GUICtrlSetOnEvent(-1, "CLOSEClicked")
$Button2 = GUICtrlCreateButton("Test Function", 120, 112, 89, 49)
GUICtrlSetOnEvent(-1, "test")
$lab1 = GUICtrlCreateLabel("", 20, 10, 50, 50)
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd
Exit

Func CLOSEClicked()
Exit
EndFunc

Func test()
    $c = 0
    While ($c <> 30)
    GUICtrlSetData ( 5, $c)
    sleep(300)
    $c = $c + 1
    WEnd
EndFunc
Link to comment
Share on other sites

The linear nature of AutoIt prevents the "msg loop" to get updated before you return from the Test() call. The code is not reentrant safe.

This code is a work around:

#include <GUIConstants.au3>
; == GUI generated with Koda ==
;Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
$Form1 = GUICreate("Test", 433, 200, 192, 125)
;GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("Exit", 112, 40, 97, 49)
;GUICtrlSetOnEvent(-1, "CLOSEClicked")
$Button2 = GUICtrlCreateButton("Test Function", 120, 112, 89, 49)
;GUICtrlSetOnEvent(-1, "Test")
$lab1 = GUICtrlCreateLabel("", 20, 10, 50, 50)
GUISetState(@SW_SHOW)
While 1
   If MsgCracker( GuiGetMsg()) = -3 Then ExitLoop
WEnd
Exit

Func MsgCracker($msg)
   Switch $msg
      case 0
        ;
      Case -3, $Button1
         $msg=-3
         CLOSEClicked()
      Case $Button2
         Test()
   EndSwitch
   Return $msg
EndFunc 
Func CLOSEClicked()
   ConsoleWrite("CLOSEClicked" & @LF)
Exit
EndFunc


Func test()
    $c = 0
    While ($c <> 30)
    GUICtrlSetData ( 5, $c)
    GUISetState()
       ;NOTE: It will take a few iteration before GuiGetMsg() passes on -3 or $button1
    If MsgCracker( GuiGetMsg()) = -3 Then ExitLoop
    sleep(300)
    $c = $c + 1
    WEnd
EndFunc
Link to comment
Share on other sites

Cool! It looks like Select `'"Case" statement with no matching "Select" statement.: ' might still be needed as I'm getting a syntax error. I tried placing one in a few different positions but no luck. Where would it go in your work around? ....Dennis

The linear nature of AutoIt prevents the "msg loop" to get updated before you return from the Test() call. The code is not reentrant safe.

This code is a work around:

#include <GUIConstants.au3>
; == GUI generated with Koda ==
;Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
$Form1 = GUICreate("Test", 433, 200, 192, 125)
;GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Button1 = GUICtrlCreateButton("Exit", 112, 40, 97, 49)
;GUICtrlSetOnEvent(-1, "CLOSEClicked")
$Button2 = GUICtrlCreateButton("Test Function", 120, 112, 89, 49)
;GUICtrlSetOnEvent(-1, "Test")
$lab1 = GUICtrlCreateLabel("", 20, 10, 50, 50)
GUISetState(@SW_SHOW)
While 1
   If MsgCracker( GuiGetMsg()) = -3 Then ExitLoop
WEnd
Exit

Func MsgCracker($msg)
   Switch $msg
      case 0
    ;
      Case -3, $Button1
         $msg=-3
         CLOSEClicked()
      Case $Button2
         Test()
   EndSwitch
   Return $msg
EndFunc 
Func CLOSEClicked()
   ConsoleWrite("CLOSEClicked" & @LF)
Exit
EndFunc
Func test()
    $c = 0
    While ($c <> 30)
    GUICtrlSetData ( 5, $c)
    GUISetState()
      ;NOTE: It will take a few iteration before GuiGetMsg() passes on -3 or $button1
    If MsgCracker( GuiGetMsg()) = -3 Then ExitLoop
    sleep(300)
    $c = $c + 1
    WEnd
EndFunc
Link to comment
Share on other sites

Cool! It looks like Select `'"Case" statement with no matching "Select" statement.: ' might still be needed as I'm getting a syntax error. I tried placing one in a few different positions but no luck. Where would it go in your work around? ....Dennis

What kinde of error do you get?

The Switch ... Case .. EndSwitch probably needs a beta version of AutoIt. I use it because I find it easier to read. You should find it in the Help File :D

The only diffrence between this code and the sample you providede is that i have moved the structure that handels the result from GuiGetMsg() out in a function. Now I can call that function several times before the first call ends (like a recursive call). You could get errors/conflicts if the rest of your code is not "independent" thought so take care.

New message handlers would go in the MsgCracker($msg) function as in

Func MsgCracker($msg)
   Switch $msg
      case 0
   ;
      Case -3, $Button1
         $msg=-3
         CLOSEClicked()
      Case $Button2
         Test()
      Case $GUI_EVENT_MOUSEMOVE;Needs #include <GUIConstants.au3>
           TraceMouse()
       Case Else
            ConsoleWrite("Unhandeled $msg:=" & $msg & @LF);Msg appeares in SciTe or when running from cmd.exe
   EndSwitch
   Return $msg
EndFunc

NOTE: If you need to do time consuming calckulations (like your test()) you shoud consider to weed that job out to another process. @neogia's coroutine.au3 udf could be one solution. Or you could take a look in my signature. :D

Link to comment
Share on other sites

NOTE: If you need to do time consuming calckulations (like your test()) you shoud consider to weed that job out to another process. @neogia's coroutine.au3 udf could be one solution. Or you could take a look in my signature. :D

Thanx Uten...I went with your suggestion of a seperate process and works like I want it to. I appreciate your time and assistance...Dennis

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