Jump to content
Sign in to follow this  
PsaltyDS

No GuiCtrlOnEvent for a progress bar

Recommended Posts

PsaltyDS

The following demo script does nothing if I click on the progress bar. What am I missing? :lmao:

; Click on progress bar test
#include <guiconstants.au3>

; Create basic GUI
$ProgDat = 0
Opt("GuiOnEventMode", 1)
$GuiId = GUICreate("Click on ProgressBar", 300, 100, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlCreateLabel("Click on the progress bar:", 10, 10, 280, 20, $SS_Center)
$ProgId = GUICtrlCreateProgress(10, 40, 280, 45, $PBS_SMOOTH)
GUICtrlSetOnEvent($ProgId, "_ProgBar")
AdlibEnable("_UpdateProg", 100)
GUISetState(@SW_SHOW, $GuiId)
While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _ProgBar()
    MsgBox(64, "Click!", "You clicked on the progress bar.")
EndFunc   ;==>_ProgBar

Func _UpdateProg()
    $ProgDat += 1
    If $ProgDat > 100 Then $ProgDat = 0
    GUICtrlSetData($ProgId, $ProgDat)
EndFunc   ;==>_UpdateProg

TIA :ph34r:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
PsaltyDS

Maybe because there is no notify style for progress bar.

Well... why not?! Get to work there buster, that's enough slack'n off out'a you! :lmao:

Actually, I had come to that conclusion and was just hoping there was some cool mystical moonman gimick that would make it happen. What I did instead was pretty cool: I had created some 50x50 .gif files to use for buttons, and the selected pic would change based on status. The in-progress one was an animated .gif loop of a little progress bar. But AutoIT won't play an animated .gif (I found out the hard way), so I translated the .gif to an .avi. Buto the .avi won't loop (I found out the hard way), so I just put a real 50x50 progress bar there, intending to get an event when it was clicked. But you don't get an event from clicking on a progress bar (I found out the hard way), so I wrote an AdlibEnable() function that updates the GuiCtrlSetPos() of the pic, so the one that's in progress bounces up and down +/-5 pixels like a loading app on the OS-X dock -- and that works! :ph34r:

; Click on progress bar test
#include <guiconstants.au3>

; Global settings
Global $aProgDat[2] = [0, 1] ; [0]=Offset, [1]=Direction
Global $ButtonX = 210, $ButtonY = 30
Opt("GuiOnEventMode", 1)

; Create basic GUI
$GuiId = GUICreate("In-Progress Test", 300, 100, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$LabelId = GUICtrlCreateLabel("Click START to begin:", 10, 40, 180, 20, $SS_Center)
$ButtonId = GUICtrlCreateButton("START", $ButtonX, $ButtonY, 60, 40)
GUICtrlSetOnEvent($ButtonId, "_Button")
GUISetState(@SW_SHOW, $GuiId)
While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Button()
    Switch GUICtrlRead($ButtonId)
        Case "START"
            GUICtrlSetData($LabelId, "Running... click STOP:")
            GUICtrlSetData($ButtonId, "STOP")
            AdlibEnable("_UpdateProg", 100)
        Case "STOP"
            GUICtrlSetData($LabelId, "Click START to begin:")
            GUICtrlSetData($ButtonId, "START")
            GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY)
            AdlibDisable()
    EndSwitch
EndFunc   ;==>_Button

Func _UpdateProg()
    $aProgDat[0] += $aProgDat[1]
    If $aProgDat[0] > 5 Then
        $aProgDat[0] = 4
        $aProgDat[1] = -1
    ElseIf $aProgDat[0] < -5 Then
        $aProgDat[0] = -4
        $aProgDat[1] = 1
    EndIf
    GUICtrlSetPos($ButtonId, $ButtonX, $ButtonY + $aProgDat[0])
EndFunc   ;==>_UpdateProg

:)

Edit: Posted the "Bouncing Button" to Scripts and Scraps, and it now has the feature you've all been waiting for... squishiness!

:geek:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×