Sign in to follow this  
Followers 0
Marco282

How to make a cancel button work during While Not InetGetInfo($INET, 2)

7 posts in this topic

#1 ·  Posted (edited)

Hello people of autoit,

I have been working on my program for quite some time now, but i am walking into some issues unfortanatly. 

The script handles downloads from a website which are quite big (700mb average) So depending on the internet speed this can take some time or not. 

I want the user to be able to hit a cancel button instead of killing the process to stop the download/program. 

The script runs 2 inetget in background mode and then does the script in the autoit tags. 

The function that all this is in is called upon by 

$downloadlatest = GUICtrlCreateButton("Download Latest",180,120,95,20)
GUICtrlSetOnEvent(-1, "DownloadLatest")
 
I already tried working with the guigetmsg() with switch and select function. Both ways no success. I also tried creating the cancel button within the while script using this: 
Global $cancelconvert = GUICtrlCreateButton("Cancel",300,150,80,20)
GUICtrlSetOnEvent(-1, "Cancel_convert")
 
and the cancel_convert function would kill the autopid. Also no success
 
How would a proper cancel button be made in such a case? Thankyou!
 While Not InetGetInfo($INET, 2) ;Loop until download is finished
 
Sleep(1000);
 $BytesReceived = InetGetInfo($INET, 0) ;Get bytes received
    $BytesReceived2 = InetGetInfo($INET2, 0) ;Get bytes received
 $BytesReceivedtotal = $BytesReceived+$BytesReceived2
$Pct = Int($BytesReceivedtotal / $FileSizetotal * 100) ;Calculate percentage
GUICtrlSetData($downloadprogressbar, $Pct)
GUICtrlSetData($downloadpercentagelabel, $Pct & "%")
 
 
 WEnd
Edited by Marco282

Share this post


Link to post
Share on other sites



Instead of using -1 with your onevent code have you tried using the actual label? Like GuiCtrlSetOnEvent($downloadlates,"DownloadLatest")? You could also try putting a ConsoleWrite or MsgBox in there somewhere after your While Not loop to make sure it's actually going through properly. Let us know if either of those helps and we can go from there.

Share this post


Link to post
Share on other sites

Instead of using -1 with your onevent code have you tried using the actual label? Like GuiCtrlSetOnEvent($downloadlates,"DownloadLatest")? You could also try putting a ConsoleWrite or MsgBox in there somewhere after your While Not loop to make sure it's actually going through properly. Let us know if either of those helps and we can go from there.

This did not matter unfortanatly. The loop is running correctly, if i but a msgbox in, it pops up everytime. 

Maybe more explanation to how its run in the script.

The mainscript calls 

$downloadlatest = GUICtrlCreateButton("Download Latest",180,120,95,20)
GUICtrlSetOnEvent(-1, "Button3Click")
 
Then button3click:
 
Func Button3Click() ;Download LATEST check
If GuiCtrlRead($highlightlatest) = $GUI_CHECKED then
   Convertcheckhighlight()
Else
   Convertcheckbroadcast()
   EndIf
EndFunc
 
 
 
Func Convertcheckbroadcast() ;Check for converting last broadcast
 
   If GuiCtrlRead($checkautoconvertlatest) = $GUI_CHECKED then
 LatestBroadcastconvert()
Else
   LatestBroadcast()
   EndIf
EndFunc
 
Then latestbroadcast is being called. Within that function is a while not during the download. 
 
 
 
 
 
 
 
And somdcomputerguy, it sounds like it would apply on my situation. Unfortanatly I dont seem to be able to implement it. Does the  HotKeySet("x", "_Interrupt")   even work when its in the mainscript and the script is running an onevent function?
 
 
 
 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

And somdcomputerguy, it sounds like it would apply on my situation. Unfortanatly I dont seem to be able to implement it. Does the  HotKeySet("x", "_Interrupt")   even work when its in the mainscript and the script is running an onevent function?

I don't have or run your script, so I don't know. Does it? Try it and see, :)

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

I don't have or run your script, so I don't know. Does it? Try it and see, :)

 

It seems to not do anything, unfortanatly. So is there anyway, i can put code in the while loop where it checks for the GUI presses? 

It must be possible and somehow i am doing it wrong.

Share this post


Link to post
Share on other sites

Sorry to bump, but look in my signature for _InetGetGUI() as an idea.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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  
Followers 0