Jump to content

AutoIt Loading Effect


Recommended Posts

How can I make a green effect bar when I press a button?

 

Spoiler
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>

Local $hGUI = GUICreate("Nút với thanh loading", 300, 100)

Local $btn = GUICtrlCreateButton("Bắt đầu", 110, 30, 80, 30)
Local $progress = GUICtrlCreateProgress(20, 70, 260, 20)

GUISetState(@SW_SHOW)

GUICtrlSetOnEvent($btn, "StartButton_Clicked")

While True
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func StartButton_Clicked()
    GUICtrlSetState($btn, $GUI_DISABLE)
    GUICtrlSetBkColor($progress, 0x0000FF)
    ProgressOn("Loading", "Đang thực hiện...", "0%", -1, -1, $GUI_PROGRESS_COLOR)
    
    For $i = 0 To 100 Step 10
        Sleep(500)
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop ; Kiểm tra sự kiện GUI trong vòng lặp
        ProgressSet($i)
    Next
    
    ProgressOff()
    GUICtrlSetState($btn, $GUI_ENABLE)
EndFunc

 


 

33333.png

Edited by 1stPK
Link to comment
Share on other sites

Search the forum for "progressbar" or the wiki and you will find a lot of hits.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

50872-how-to-post-code-on-the-forum/

https://www.autoitscript.com/autoit3/docs/functions/GUISetOnEvent.htm

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>

Local $hGUI = GUICreate("Nút với thanh loading", 300, 100)

Local $btn = GUICtrlCreateButton("Bắt đầu", 110, 30, 80, 30)
Local $progress = GUICtrlCreateProgress(20, 70, 260, 20)

GUISetState(@SW_SHOW)

;~ GUICtrlSetOnEvent($btn, "StartButton_Clicked")

While True
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $btn
            StartButton_Clicked()

    EndSwitch
WEnd

Func StartButton_Clicked()
    GUICtrlSetState($btn, $GUI_DISABLE)
    GUICtrlSetBkColor($progress, 0x0000FF)
;~  ProgressOn ( "title", "maintext" [, "subtext" [, x pos [, y pos [, opt]]]] )
    ProgressOn("Loading", "Đang thực hiện...", "0%", -1, -1)

    For $i = 0 To 100 Step 10
        Sleep(500)
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop ; Kiểm tra sự kiện GUI trong vòng lặp
        ProgressSet($i)
    Next

    ProgressOff()
    GUICtrlSetState($btn, $GUI_ENABLE)
EndFunc   ;==>StartButton_Clicked

 

I know that I know nothing

Link to comment
Share on other sites

I think he meant something like this :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>

HotKeySet("{ESC}", Terminate)

Opt("GUIOnEventMode", True)

Local $hGUI = GUICreate("Nút với thanh loading", 300, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, Terminate)

Local $btn = GUICtrlCreateButton("Bắt đầu", 110, 30, 80, 30)
GUICtrlSetOnEvent(-1, "StartButton_Clicked")

Local $progress = GUICtrlCreateProgress(20, 70, 260, 20)
GUISetState()

While Sleep(100)
WEnd

Func StartButton_Clicked()
  GUICtrlSetState($btn, $GUI_DISABLE)
  For $i = 0 To 100 Step 10
    GUICtrlSetData($progress, $i)
    Sleep(500)
  Next
  GUICtrlSetState($btn, $GUI_ENABLE)
EndFunc   ;==>StartButton_Clicked

Func Terminate()
  Exit
EndFunc   ;==>Terminate

ps. you cannot interrupt a secondary loop from a GUI.  Only the main GUI loop can be interrupted (unless you use a "hack" like I did)

Edited by Nine
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...