wakillon Posted September 11, 2010 Share Posted September 11, 2010 I want replace my download button by a cancel buttonBut when i click on cancel button nothing happens ...I'm lost, since 3 days I tearing my hair !expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt ( "GuiOnEventMode", 1 ) Global $_GUI,$_DownloadButton, $_Cancel = FALSE, $_CancelButton _Gui ( ) While 1 Sleep ( 10 ) WEnd Func _Gui ( ) $_GUI = GUICreate ( "GUI", 400, 200 ) GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit" ) $_DownloadButton = GUICtrlCreateButton ( "Download", 10, 90, 180, 24 ) GUICtrlSetOnEvent ( $_DownloadButton, "_Download" ) GUICtrlSetState ( $_DownloadButton, $GUI_ENABLE ) $_CancelButton = GUICtrlCreateButton ( "Cancel Download", 10, 90, 180, 24 ) GUICtrlSetOnEvent ( $_CancelButton, "_CancelDownload" ) GUICtrlSetState ( $_CancelButton, $GUI_DISABLE ) GUICtrlSetState ( $_CancelButton, $GUI_HIDE ) GUISetState ( @SW_SHOW ) EndFunc ;==> _Gui ( ) Func _CancelDownload ( ) ConsoleWrite ( "+>---- Function _CancelDownload ( ) : " & @Crlf ) $_Cancel=TRUE ConsoleWrite ( "+>---- $_Cancel : " & $_Cancel & @Crlf ) EndFunc Func _Download ( ) ConsoleWrite ( "+>---- Function _Download ( ) : " & @Crlf ) GUICtrlSetState ( $_DownloadButton, $GUI_DISABLE ) GUICtrlSetState ( $_DownloadButton, $GUI_HIDE ) GUICtrlSetState ( $_CancelButton, $GUI_SHOW ) GUICtrlSetState ( $_CancelButton, $GUI_ENABLE ) While 1 If $_Cancel = TRUE Then $_MsgBox = MsgBox ( 4, "Cancel", "Are you sure to Cancel Download ?" ) If $_MsgBox = 6 Then $_Cancel = FALSE ExitLoop EndIf EndIf Sleep ( 10 ) WEND GUICtrlSetState ( $_CancelButton, $GUI_DISABLE ) GUICtrlSetState ( $_CancelButton, $GUI_HIDE ) GUICtrlSetState ( $_DownloadButton, $GUI_SHOW ) GUICtrlSetState ( $_DownloadButton, $GUI_ENABLE ) EndFunc ;==> _Download ( ) Func _Exit ( ) GUIDelete ( $_GUI ) Exit EndFunc ;==> _Exit ( )I saw during my research that Melba23 was a great specialist of this kind of problems ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Tvern Posted September 11, 2010 Share Posted September 11, 2010 (edited) The problem is that the _CancelDownload ( ) function has to wait for the _Download function to finish before it's called and by then it's too late. I'll cook up an example to work around it. edit: Blast! too late! here was my suggestion: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt ( "GuiOnEventMode", 1 ) Global $_GUI,$_ToggleButton, $_Cancel = True _Gui ( ) While 1 If Not $_Cancel Then _Download ( ) EndIf Sleep ( 10 ) WEnd Func _Gui ( ) $_GUI = GUICreate ( "GUI", 400, 200 ) GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit" ) $_ToggleButton = GUICtrlCreateButton ( "Download", 10, 90, 180, 24 ) GUICtrlSetOnEvent ( $_ToggleButton, "_ToggleDownload" ) GUISetState ( @SW_SHOW ) EndFunc ;==> _Gui ( ) Func _ToggleDownload ( ) ConsoleWrite ( "+>---- Function _ToggleDownload ( ) : " & @Crlf ) $_Cancel = Not $_Cancel If $_Cancel Then GUICtrlSetData($_ToggleButton,"Download") Else GUICtrlSetData($_ToggleButton,"Cancel") EndIf ConsoleWrite ( "+>---- $_Cancel : " & $_Cancel & @Crlf ) EndFunc Func _Download ( ) ConsoleWrite ( "+>---- Function _Download ( ) : " & @Crlf ) While 1 If $_Cancel = TRUE Then $_MsgBox = MsgBox ( 4, "Cancel", "Are you sure to Cancel Download ?" ) If $_MsgBox = 6 Then ExitLoop Else $_Cancel = False EndIf EndIf Sleep ( 10 ) WEnd EndFunc ;==> _Download ( ) Func _Exit ( ) GUIDelete ( $_GUI ) Exit EndFunc ;==> _Exit ( ) Pretty much the same idea. Edited September 11, 2010 by Tvern Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 11, 2010 Moderators Share Posted September 11, 2010 wakillon,I would do something along these lines: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt ( "GuiOnEventMode", 1 ) Global $_GUI,$_DualButton, $_Cancel = FALSE _Gui ( ) While 1 If $_Cancel = TRUE Then $_MsgBox = MsgBox ( 4, "Cancel", "Are you sure to Cancel Download ?" ) If $_MsgBox = 6 Then $_Cancel = FALSE ExitLoop EndIf EndIf Sleep ( 10 ) WEnd Func _Gui ( ) $_GUI = GUICreate ( "GUI", 400, 200 ) GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit" ) $_DualButton = GUICtrlCreateButton ( "Download", 10, 90, 180, 24 ) GUICtrlSetOnEvent ( $_DualButton, "_Button" ) GUISetState() EndFunc Func _Button ( ) If GUICtrlRead($_DualButton) = "Download" Then ConsoleWrite ( "+>---- Function _Download ( ) : " & @Crlf ) GUICtrlSetData($_DualButton, "Cancel Download") Else ConsoleWrite ( "+>---- Function _CancelDownload ( ) : " & @Crlf ) $_Cancel=TRUE ConsoleWrite ( "+>---- $_Cancel : " & $_Cancel & @Crlf ) GUICtrlSetData($_DualButton, "Download") EndIf EndFunc ;==> _Download ( ) Func _Exit ( ) Exit EndFunc ;==> _Exit ( )Have you read the Interrupting a running function tutorial in the Wiki? Lots of good info on how to do it in there. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wakillon Posted September 11, 2010 Author Share Posted September 11, 2010 Wow 12 minutes and 2 working solutions Melba23 and Tvern thank you very much !You're great and fast ! what i'm stupid by moment...Thanks again ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts 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