Jump to content

How to prevent a label hiding behind a progress bar when updating it


Recommended Posts

Hello :bye:,

I am using this code to make a nice progress bar which also tells what is going on:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
GUICreate("GUI", 294, 69, 192, 124)
$idProgressBar = GUICtrlCreateProgress(8, 24, 278, 17)
$idLabel = GUICtrlCreateLabel("0", 8, 24, 276, 17, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 0 To 10
    GUICtrlSetData($idProgressBar, CalcPercent($i, 10))
    GUICtrlSetData($idLabel, $i)
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func CalcPercent($iPartDone, $iTotal, $iRoundToDecimalPlace = 1)
    Return Round(($iPartDone / $iTotal) * 100, $iRoundToDecimalPlace)
EndFunc

But the label hides behind the progress bar when I update it :(, How can I prevent this?

 

Thanks in Advance, TD :)

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

Do not put the label and the progressbar on the same screen position ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

Then please search the forum for progressbars. I'm sure this problem has alfready been solved.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.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 (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

I found some solutions, they use GDI+ or some complicated DllCalls... This is the best solution I found but it removes that fancy animation :(. I am still looking for a solution which does this without removing the animation, TD :)

 

P.S Forum search sucks! Instead use site:autoitscript.com/forum <Insert your problem here> in google.

Edited by TheDcoder
Fixed broken link

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

You can use a child gui:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("GUI", 294, 69, 192, 124)
$idProgressBar = GUICtrlCreateProgress(8, 24, 278, 17)
$hGUI_c = GUICreate("", 20, 17, (8 + 278 - 20) / 2, 24, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI)
GUISetBkColor(0x989898, $hGUI_c)
$idLabel = GUICtrlCreateLabel("0", 0, 0, 20, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
_WinAPI_SetLayeredWindowAttributes($hGUI_c, 0x989898)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOWNA, $hGUI_c)
#EndRegion ### END Koda GUI section ###

For $i = 0 To 10
    GUICtrlSetData($idProgressBar, CalcPercent($i, 10))
    GUICtrlSetData($idLabel, $i)
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func CalcPercent($iPartDone, $iTotal, $iRoundToDecimalPlace = 1)
    Return Round(($iPartDone / $iTotal) * 100, $iRoundToDecimalPlace)
EndFunc

 

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 post
Share on other sites

@UEZ Can you explain the bold part:

GUICreate("", 20, 17, (8 + 278 - 20) / 2, 24, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI)

Or give me the formula for calculating left & top :)

 

TD :)

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

How to find the center on the progressbar?

$idProgressBar = GUICtrlCreateProgress(8, 24, 278, 17)
$hGUI_c = GUICreate("", 20, 17, (8 + 278 - 20) / 2, 24, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI)

(8 + 278 - 20) / 2

8 = left position of pb (start x position)

278 = width of pb

20 = width of child gui

-> 266 / 2 = 133

133 is the x position of the child gui (left upper corner).

Checked?

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 post
Share on other sites

@UEZ Am I doing something wrong?:

; Includes
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>

; Main GUI

Global $hGUI = GUICreate("GUI", 528, 287)
Global $idStatusBar = GUICtrlCreateProgress(113,61,325,20)
Global $idStatusText = GUICtrlCreateLabel("Test",113,64,325,16,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$hLayerGUI = GUICreate("", 20, 17, (113 + 325 - 20) / 2, 61, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI)
GUISetBkColor(0x989898, $hLayerGUI)
_WinAPI_SetLayeredWindowAttributes($hLayerGUI, 0x989898)
GUICtrlCreateButton("Button",221,83,100,26)

GUISetState(@SW_SHOW, $hGUI)

For $i = 0 To 100 Step 10
    SetStatus($i)
    Sleep(250)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func SetStatus($fStatus = 0, $sStatus = Default)
    If Not $sStatus = Default Then GUICtrlSetData($idStatusText, $sStatus)
    GUICtrlSetData($idStatusBar, $fStatus)
EndFunc   ;==>SetStatus

Where is the button & the status label? TD :)

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

Try this:

Global $hGUI = GUICreate("GUI", 528, 287)
Global $idStatusBar = GUICtrlCreateProgress(113,61,325,20)
Global Const $iColor_Bg = 0xB1B1B1
$hLayerGUI = GUICreate("", 325, 20, 113, 61, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_MDICHILD), $hGUI)
GUISetBkColor($iColor_Bg, $hLayerGUI)
Global $idStatusText = GUICtrlCreateLabel("Test",0,0,325,16,$SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlCreateButton("Button",221,83,100,26)
_WinAPI_SetLayeredWindowAttributes($hLayerGUI, $iColor_Bg)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOWNA, $hLayerGUI)

If you want to position a control on the child GUI you have to think differently. The child GUI hasn't the same width and height as the parent GUI and if you position the controls outside the child GUI dimension you cannot see the controls. Further you have to show the child GUI.

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 post
Share on other sites

Another try:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
GUICreate("GUI", 294, 69, 192, 124)
$idProgressBar = GUICtrlCreateProgress(8, 24, 278, 24, $PBS_SMOOTH)
$idLabel = GUICtrlCreateLabel("0", 8, 24, 276, 22, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 0 To 10
    GUICtrlSetData($idProgressBar, CalcPercent($i, 10))
    If $i=5 Then GUICtrlSetColor($idLabel,0xffffff)
    GUICtrlSetData($idLabel, $i)
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func CalcPercent($iPartDone, $iTotal, $iRoundToDecimalPlace = 1)
    Return Round(($iPartDone / $iTotal) * 100, $iRoundToDecimalPlace)
EndFunc

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MrCreatoR
      This UDF allows to create formatted label using pseudo element RichLabel (RichEdit actually). Formating is set by using special modificator similar to <font> tag in Html.
      Notes: This UDF is a transformation-continuation of related UDF


      Example:
      Download:
      GUIRichLabel_1.2.zip
      Small syntax related fix: GUIRichLabel_1.1.zip
      GUIRichLabel_1.1.zip
       
      History version:
    • By BrewManNH
      I have created a UDF that will allow you to easily create a customizable GUI with either a standard progress bar or a marquee style progress bar. You can change the size and back ground color of the GUI, as well as the font, font size, and color of the text. The function doesn't require any parameters to operate, but the default text is very generic so you probably would want to set that at the very least.
    • By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
    • By WoodGrain
      Hi guys,
      I'm learning about GUI's, I'm trying the below code, the idea being if I press the letter "e" while I have the GUI open I want the label color to change to green (I'm using a UDF for label colors). But every time I press "e" on my keyboard I just get a "ding" sound from my speakers and nothing changes with the label.
      I've looked at using something like "While GUIGetMsg() <> $GUI_EVENT_CLOSE" as I've seen it in other code instead of "While 1", but I don't think it's relevant.
      #include <GUIConstantsEx.au3>; for GUI... #include <GUIRichLabel.au3>; UDF for rich text label fonts #include <Misc.au3>; for _IsPressed $myLetter = "e" $hGUI = GUICreate("test", 700, 60) $lbl2 = _GUICtrlRichLabel_Create($hGUI, '<font color="purple">' & $myLetter & '</font>', 10, 10); , 260, 25 GUISetState(@SW_SHOW) Local $hDLL = DllOpen("user32.dll") While 1 if _IsPressed(Hex($myLetter), $hDLL) Then While _IsPressed(Hex($myLetter), $hDLL) Sleep(250) WEnd _GUICtrlRichLabel_SetData($lbl2, '<font color="green">' & $myLetter & '</font>') Sleep(2000) DllClose($hDLL) Exit EndIf Sleep(50) WEnd DllClose($hDLL) I am using an array of letters that I'm wanting to do this for, but as I can't get it to work I've stripped it down to the simplest code I can think of to try and get this working first. Appreciate any help.
      Thanks!
    • By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
×
×
  • Create New...