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 - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
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 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

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

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 - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
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 comment
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 - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
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 comment
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 - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
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 comment
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 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

×
×
  • Create New...