fgthhhh Posted August 14, 2010 Share Posted August 14, 2010 I want to close my program any time by click on X button, but it only work after my program finished working. the only way to quit is right click on its icon and choose quit. how can i do it? thx Link to comment Share on other sites More sharing options...
kaotkbliss Posted August 14, 2010 Share Posted August 14, 2010 You need to look for the $GUI_EVENT_CLOSE in the guigetmsg() 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
fgthhhh Posted August 14, 2010 Author Share Posted August 14, 2010 no, $GUI_EVENT_CLOSE is only working after my function finished. i need something stronger can exit while even running such as right click on its icon and choose quit Link to comment Share on other sites More sharing options...
smashly Posted August 14, 2010 Share Posted August 14, 2010 Hi, Post some code so ppl can advise you on how to accomplish what your after.. It would make life easier for those that would like to help you. Cheers Link to comment Share on other sites More sharing options...
fgthhhh Posted August 14, 2010 Author Share Posted August 14, 2010 (edited) it look like this #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUICreate("My GUI") ; will create a dialog box that when displayed is centered $button = GUICtrlCreateButton( "run" , 50, 50, 100) GUISetState(@SW_SHOW) ; will display an empty dialog box While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit If $msg = $button Then Sleep(10000) WEnd when i click on button "run" it will sleep for 10s even i click on X button i want to exit instantly when i click X button Edited August 14, 2010 by fgthhhh Link to comment Share on other sites More sharing options...
smashly Posted August 14, 2010 Share Posted August 14, 2010 Hi, Instead of trying to do one big sleep(), try doing multiple small sleeps and check for $GUI_EVENT_CLOSE. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGui = GUICreate("My GUI") $button = GUICtrlCreateButton( "run" , 50, 50, 100) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $button GUICtrlSetState($button, $GUI_DISABLE) For $i = 1 To 100 If Not Mod($i, 10) Then WinSetTitle($hGui, "", "My GUI asleep for: " & $i / 10 & " seconds") Sleep(100) If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit Next WinSetTitle($hGui, "", "My GUI") GUICtrlSetState($button, $GUI_ENABLE) EndSwitch WEnd Cheers Link to comment Share on other sites More sharing options...
fgthhhh Posted August 14, 2010 Author Share Posted August 14, 2010 thanks for the solution.it's a nice way if i have a long function should i put "check for $GUI_EVENT_CLOSE" in every line? or can i have other way because its size will bigger. as i said. right click on icon and choose exit is perfect way, can i put it in X button so i won't need insert the $GUI_EVENT_CLOSE line Link to comment Share on other sites More sharing options...
FlyinRiz Posted August 14, 2010 Share Posted August 14, 2010 thanks for the solution.it's a nice wayif i have a long function should i put "check for $GUI_EVENT_CLOSE" in every line? or can i have other way because its size will bigger.as i said. right click on icon and choose exit is perfect way, can i put it in X button so i won't need insert the $GUI_EVENT_CLOSE lineEven if you add another button, you'll run into the same problem. You need to repeat the While 1 loop as quick as possible because that's the only way the program can grab the next message. You could also look into OnEvent instead. That would allow a button to interrupt your script.-Aaron Link to comment Share on other sites More sharing options...
fgthhhh Posted August 16, 2010 Author Share Posted August 16, 2010 i'm going to do an auto-shutdown program but i can't close my program while pressed start. pls help me, this is my code expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGui = GUICreate("My GUI") Global $sec = @SEC $clock = GUICtrlCreateLabel( @HOUR &":"& @MIN &":"& $sec, 260, 40, 120, 40) GUICtrlSetFont(-1, 20) $start = GUICtrlCreateButton( "Start", 150,260,100) GUICtrlCreateLabel( "Hour(s)", 250,133,50) $hour = GuiCtrlCreateInput("0", 200, 130, 40, 20) GuiCtrlCreateUpDown(-1) GUICtrlCreateLabel( "Minute(s)", 350,133,50) $minute = GuiCtrlCreateInput("10", 300, 130, 40, 20) GuiCtrlCreateUpDown(-1) GUISetState(@SW_SHOW) GUISetState(@SW_SHOW) While 1 If $sec <> @SEC Then GUICtrlSetData( $clock , @HOUR &":"& @MIN &":"& @SEC) $sec = @SEC EndIf Global $eMSG = GUIGetMsg() Switch $eMSG Case $GUI_EVENT_CLOSE _exit() Case $start start() EndSwitch WEnd Func start() $total = ( GUICtrlRead($hour)*60 + GUICtrlRead($minute) )*60 For $i = 0 to $total If $eMSG = $GUI_EVENT_CLOSE Then Exit Sleep(1000) Next Exit EndFunc Link to comment Share on other sites More sharing options...
Foxhound Posted August 16, 2010 Share Posted August 16, 2010 (edited) It should be just Exit instead of _Exit() As for the $GUI_EVENT_CLOSE, I suggest you do a While loop to check for any exit events Edited August 16, 2010 by Foxhound [quote]Quick YouTube To MP3 | Lyrics Finder | Internet Radio Player | GetWeather | TinyURLifier[/quote] Link to comment Share on other sites More sharing options...
fgthhhh Posted August 16, 2010 Author Share Posted August 16, 2010 i put this line "If $eMSG = $GUI_EVENT_CLOSE Then Exit" but somehow it doesn't work? can you help me why? Link to comment Share on other sites More sharing options...
JackDinn Posted August 16, 2010 Share Posted August 16, 2010 (edited) Its because of your pause ("sleep(1000)") in the loop , it messes up the get message. Try this :- expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGui = GUICreate("My GUI") Global $sec = @SEC $clock = GUICtrlCreateLabel(@HOUR & ":" & @MIN & ":" & $sec, 260, 40, 120, 40) GUICtrlSetFont(-1, 20) $start = GUICtrlCreateButton("Start", 150, 260, 100) GUICtrlCreateLabel("Hour(s)", 250, 133, 50) $hour = GUICtrlCreateInput("0", 200, 130, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlCreateLabel("Minute(s)", 350, 133, 50) $minute = GUICtrlCreateInput("10", 300, 130, 40, 20) GUICtrlCreateUpdown(-1) GUISetState(@SW_SHOW) GUISetState(@SW_SHOW) While 1 If $sec <> @SEC Then GUICtrlSetData($clock, @HOUR & ":" & @MIN & ":" & @SEC) $sec = @SEC EndIf Global $eMSG = GUIGetMsg() Switch $eMSG Case $GUI_EVENT_CLOSE Exit Case $start start() EndSwitch WEnd Func start() GUICtrlSetData($start, "Stop") $total = (GUICtrlRead($hour) * 60 + GUICtrlRead($minute)) * 60000 ; get time duration in milliseconds $total_count = TimerInit() ; start time count While 1 If $sec <> @SEC Then GUICtrlSetData($clock, @HOUR & ":" & @MIN & ":" & @SEC) GUICtrlSetColor($clock, 0xff0000) $sec = @SEC EndIf $eMSG = GUIGetMsg() If $eMSG = $start Then GUICtrlSetData($start, "Start") GUICtrlSetColor($clock, 0x000000) Return EndIf If $eMSG = $GUI_EVENT_CLOSE Then Exit If TimerDiff($total_count) >= $total Then MsgBox(0, '', "Stop") Exit EndIf WEnd Exit EndFunc ;==>start Edited August 16, 2010 by JackDinn Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
fgthhhh Posted August 16, 2010 Author Share Posted August 16, 2010 really thanks, mate. it worked perfectly!!! :D:D:D Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now