Jump to content

[Solved]Problem with GUIOnEventMode


Fire
 Share

Recommended Posts

Hi Great Autoit Community.

Again problem catch me witH GUIOnEventMode().

Here is my test script.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>


Opt('MustDeclareVars', 1)


main()



Func main()

    Opt("GUIOnEventMode", 1)

    Local $Form1,$Tab1,$TabSheet1,$TabSheet2,$TabSheet3,$Label1,$Label2,$Input1,$Button1,$Button2,$Button3,$Progress1


$Form1 = GUICreate("TEST", 599, 299, 354, 298, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetBkColor(0x000000)





$Tab1 = GUICtrlCreateTab(0, 0, 201, 25)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("")
$Label1 = GUICtrlCreateLabel("ENTER Link to file", 16, 72, 108, 19, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)
$Label2 = GUICtrlCreateLabel("Where to save?", 16, 152, 112, 19, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)
$Input1 = GUICtrlCreateInput("", 168, 72, 337, 21, BitOR($ES_AUTOHSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))



;$Input2 = GUICtrlCreateInput("Input2", 168, 152, 337, 21, BitOR($ES_AUTOHSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button1 = GUICtrlCreateButton("Choose", 520, 152, 49, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button2 = GUICtrlCreateButton("Download", 56, 240, 121, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetOnEvent(-1,"download")
$Button3 = GUICtrlCreateButton("Cancel", 400, 240, 137, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetOnEvent(-1, "CANCEL")
$Progress1 = GUICtrlCreateProgress(88, 192, 433, 25, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)



While 1
Sleep(10)
    WEnd
EndFunc; <==main()




Func CANCEL()
MsgBox(64,"","Cancel button Clicked!",10)
EndFunc; <==CANCEL()






Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit
    EndSelect

EndFunc ;==>SpecialEvents




Func download()
Local $Input1,$hsize,$i,$Progress1,$hvar

$hsize=InetGetSize(GUICtrlRead($Input1),1)

            MsgBox(64,"FOR KNOW WHATS GOING",$hsize & " byte") ;debug

For $i=StringLen(GUICtrlRead($Input1)) To 0 step - 1
MsgBox(64,"",GUICtrlRead($Input1)) ;also it returns for me 0. something wrong :(
If StringMid(GUICtrlRead($Input1),$i,1) = "/" Then
$hvar=StringMid(GUICtrlRead($Input1),$i + 1,StringLen(GUICtrlRead($Input1)) - $i + 1)
MsgBox(64,"",$hvar)
$i=0

        EndIf

    Next
InetGet(GUICtrlRead($Input1),@ScriptDir&"\"&$hvar,1,1)

$i=0
Do
$i+=1
Sleep(800)
GUICtrlSetData($Progress1,FileGetSize(@ScriptDir&"\"&$hvar) / $hsize * 100)
Until FileGetSize(@ScriptDir&"\"&$hvar) = $hsize
EndFunc; <==download()

I use in it GUIOnEventMode() and as result problem catch me.

Some Controls didn`t works in it.For example if i clicked in download button it didn`t works anymore.(But Msgbox() appears)

I think problem related in guictrlread() in GUIOnEventMode.

Also i cannot retrive input from $input1. guictrlread($input1) returns for me 0 which means fail to obtain input from control.

Whats wrong in it ?What i`m missing or what i`m doing wrong?

Also i check help file too.I cannot catch whats wrong.

Any tips,hints would be super as always.And thanks in advance.

Edited by Fire
[size="5"] [/size]
Link to comment
Share on other sites

  • Moderators

Fire,

I think problem related in guictrlread() in GUIOnEventMode

I think problem related to Fire declaring variables in wrong scope! :P

Take a look at your code:

Func main()

    Local [...] $Input1, [...] ; So $iInput1 is only available within this function

;...

Func download()

    Local $Input1, [...] ; And this $Input1 will remain forever undeclared as there is no such control in this function

    $hsize = InetGetSize(GUICtrlRead($Input1), 1)

Try declaring $Input1 as a Global variable and remove the 2 Local declarations. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi Great Autoit Community.

Again problem catch me witH GUIOnEventMode().

Here is my test script.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>


Opt('MustDeclareVars', 1)


main()



Func main()

    Opt("GUIOnEventMode", 1)

    Local $Form1,$Tab1,$TabSheet1,$TabSheet2,$TabSheet3,$Label1,$Label2,$Input1,$Button1,$Button2,$Button3,$Progress1


$Form1 = GUICreate("TEST", 599, 299, 354, 298, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetBkColor(0x000000)





$Tab1 = GUICtrlCreateTab(0, 0, 201, 25)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
GUICtrlCreateTabItem("")
$Label1 = GUICtrlCreateLabel("ENTER Link to file", 16, 72, 108, 19, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)
$Label2 = GUICtrlCreateLabel("Where to save?", 16, 152, 112, 19, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)
$Input1 = GUICtrlCreateInput("", 168, 72, 337, 21, BitOR($ES_AUTOHSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))



;$Input2 = GUICtrlCreateInput("Input2", 168, 152, 337, 21, BitOR($ES_AUTOHSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button1 = GUICtrlCreateButton("Choose", 520, 152, 49, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button2 = GUICtrlCreateButton("Download", 56, 240, 121, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetOnEvent(-1,"download")
$Button3 = GUICtrlCreateButton("Cancel", 400, 240, 137, 25, BitOR($WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUICtrlSetOnEvent(-1, "CANCEL")
$Progress1 = GUICtrlCreateProgress(88, 192, 433, 25, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)



While 1
Sleep(10)
    WEnd
EndFunc; <==main()




Func CANCEL()
MsgBox(64,"","Cancel button Clicked!",10)
EndFunc; <==CANCEL()






Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit
    EndSelect

EndFunc ;==>SpecialEvents




Func download()
Local $Input1,$hsize,$i,$Progress1,$hvar

$hsize=InetGetSize(GUICtrlRead($Input1),1)

            MsgBox(64,"FOR KNOW WHATS GOING",$hsize & " byte") ;debug

For $i=StringLen(GUICtrlRead($Input1)) To 0 step - 1
MsgBox(64,"",GUICtrlRead($Input1)) ;also it returns for me 0. something wrong :(
If StringMid(GUICtrlRead($Input1),$i,1) = "/" Then
$hvar=StringMid(GUICtrlRead($Input1),$i + 1,StringLen(GUICtrlRead($Input1)) - $i + 1)
MsgBox(64,"",$hvar)
$i=0

        EndIf

    Next
InetGet(GUICtrlRead($Input1),@ScriptDir&"\"&$hvar,1,1)

$i=0
Do
$i+=1
Sleep(800)
GUICtrlSetData($Progress1,FileGetSize(@ScriptDir&"\"&$hvar) / $hsize * 100)
Until FileGetSize(@ScriptDir&"\"&$hvar) = $hsize
EndFunc; <==download()

I use in it GUIOnEventMode() and as result problem catch me.

Some Controls didn`t works in it.For example if i clicked in download button it didn`t works anymore.(But Msgbox() appears)

I think problem related in guictrlread() in GUIOnEventMode.

Also i cannot retrive input from $input1. guictrlread($input1) returns for me 0 which means fail to obtain input from control.

Whats wrong in it ?What i`m missing or what i`m doing wrong?

Also i check help file too.I cannot catch whats wrong.

Any tips,hints would be super as always.And thanks in advance.

You made some mistakes! If you declare a variable within a function the variable is only valid within that function!

$Input1 is declared in func main() and func download! Of course the result is 0!

Solution:

Declare $Input1 before main() as global and remove the declaration of $Input1 within the functions!

BR,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

:party: Thanks for help Melba23 .Yes after your post i solve it.

But i get another problem:(

While downloading in progress in background i mean in func download()

InetGet(GUICtrlRead($Input1),@ScriptDir&"\"&$hvar,1,1)
$Button3 (Cancel) Button is not clickable.

It waits finish func download() and after this it is clickable.Why this occurs i just wondering too?.:mellow:

Thank you very much Melba23 :P

edit: Thank you very much too UEZ.Aha.I solve it after helpfull posts.

Edited by Fire
[size="5"] [/size]
Link to comment
Share on other sites

Because of your Do / Until loop! The script is running in that particular loop until it is finished and there is no check for any button!

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks again for quick replay UEZ.Is it possible bypass it while downloading is active?Otherwise Cancel button still unclickable in this situation.

Thanks very much to all again.

edit:I think this can be done with hotkeyset or with GUISetAccelerators am i right?Or is here another way to solve it?

Edited by Fire
[size="5"] [/size]
Link to comment
Share on other sites

I modified your script a little bit:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)

Global $Form1, $Tab1, $TabSheet1, $TabSheet2, $TabSheet3, $Label1, $Label2, $Button1, $Button2
Global $Input1, $Button3, $Progress1, $nMsg

main()

Func main()

    $Form1 = GUICreate("TEST", 599, 299, 354, 298, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))

    GUISetBkColor(0x000000)

    $Tab1 = GUICtrlCreateTab(0, 0, 201, 25)
    GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
    $TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
    $TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    $TabSheet3 = GUICtrlCreateTabItem("TabSheet3")
    GUICtrlCreateTabItem("")
    $Label1 = GUICtrlCreateLabel("ENTER Link to file", 16, 72, 108, 19, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
    GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
    GUICtrlSetColor(-1, 0xFF0000)
    $Label2 = GUICtrlCreateLabel("Where to save?", 16, 152, 112, 19, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
    GUICtrlSetFont(-1, 8, 400, 0, "Arial Unicode MS")
    GUICtrlSetColor(-1, 0xFF0000)
    $Input1 = GUICtrlCreateInput("", 168, 72, 337, 21, BitOR($ES_AUTOHSCROLL, $WS_BORDER, $WS_CLIPSIBLINGS))

    ;$Input2 = GUICtrlCreateInput("Input2", 168, 152, 337, 21, BitOR($ES_AUTOHSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS))
    $Button1 = GUICtrlCreateButton("Choose", 520, 152, 49, 25, BitOR($WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
    $Button2 = GUICtrlCreateButton("Download", 56, 240, 121, 25, BitOR($WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
    $Button3 = GUICtrlCreateButton("Cancel", 400, 240, 137, 25, BitOR($WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
    $Progress1 = GUICtrlCreateProgress(88, 192, 433, 25, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Button2
                Download()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc ;==>main


Func download()
    Local $hsize, $i, $hvar, $url, $download

    $url = GUICtrlRead($Input1)

    $hsize = InetGetSize($url, 1)

    MsgBox(64, "FOR KNOW WHATS GOING", $hsize & " byte") ;debug

    $hvar = StringMid($url, StringInStr($url, "/", 0, -1) + 1, StringLen($url))
    $download = InetGet($url, @ScriptDir & "\" & $hvar, 1, 1)

    Do
        GUICtrlSetData($Progress1, InetGetInfo($download, 0) / $hsize * 100)
        Sleep(100)
        If GUIGetMsg() = $Button3 Then ExitLoop
    Until InetGetInfo($download, 2)
    InetClose($download)
    GUICtrlSetData($Progress1, 0)
EndFunc ;==>download

I hope it helps you.

BR,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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