1stPK Posted January 11 Share Posted January 11 (edited) 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 Edited January 12 by 1stPK Link to comment Share on other sites More sharing options...
water Posted January 11 Share Posted January 11 Search the forum for "progressbar" or the wiki and you will find a lot of hits. 1stPK 1 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 More sharing options...
ioa747 Posted January 11 Share Posted January 11 50872-how-to-post-code-on-the-forum/ https://www.autoitscript.com/autoit3/docs/functions/GUISetOnEvent.htm expandcollapse popup#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 1stPK 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Nine Posted January 11 Share Posted January 11 (edited) 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 January 11 by Nine 1stPK 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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