Jump to content

Progressbar with GDIplus


ProgAndy
 Share

Recommended Posts

This is a port of the example Script in How about a progressbar like this? to an UDF.

These are the functions:

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.12.0
    Author:         Prog@ndy
    after Script from nobbe ( 2008 in http://www.autoitscript.com/forum/index.php?s=&showtopic=64703&view=findpost&p=485031 )
    
    Script Function:  A UDF for colored Progressbars with GDIPlus
    
    Remarks: Theres an example from Line 22 to line 112 ( between the first #Region - #Endregion Tags
    
#ce ----------------------------------------------------------------------------
;===============================================================================
;
; Function Name:   _ProgressCreate
; Description::    Creates a GDIplus Progressbar
; Parameter(s):    $x     : left
;                  $y     : top
;                  $w     : width
;                  $h     : height
;                  $Col     : [Optional] Top color of the foreground gradient
;                  $GradCol : [Optional] Bottom color of the foreground gradient
;                  $BG      : [Optional] Top color of the background gradient
;                  $GradBG  : [Optional] Bottom color of the background gradient
; Requirement(s):  GDIplus
; Return Value(s): Success: ID of Progressbar, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressDelete
; Description::    Deletes a GDI+ Progressbar
; Parameter(s):    $ID      : ID of Progressbar
; Requirement(s):  GDIplus
; Return Value(s): Sucess: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSetColors(
; Description::    Sets gradients as foreground and background
; Parameter(s):    $ID      : ID of Progressbar
;                  $Col     : Top color of the foreground gradient
;                  $GradCol : Bottom color of the foreground gradient
;                  $BG      : Top color of the background gradient
;                  $GradBG  : Bottom color of the background gradient
;             If $Col or $GradCol is -1, the foreground gradient isn't changed
;             If $BG or $GradBG is -1, the background gradient isn't changed
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSetImages(
; Description::    Sets images as foreground and background by Path
; Parameter(s):    $ID : ID of Progressbar
;                  $ForeBmp : Path to image , empty String "" To leave the old
;                             The foreground image
;                  $BackBmp : [Optional] Path to image , empty String "" To leave the old
;                             The background image
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSetHBitmaps(
; Description::    Sets previously loaded GDIplus Images / bitmaps as foreground and background
; Parameter(s):    $ID : ID of Progressbar
;                  $ForeBmp : Handle to GDIplus -image or -bitmap , -1 To leave the old
;                             The foreground image
;                  $BackBmp : [Optional] Handle to GDIplus -image or -bitmap , -1 To leave the old
;                             The background image
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSetText(
; Description::    Sets the text to be shown
; Parameter(s):    $ID : ID of Progressbar
;                  $text:  -> TRUE : Show percent
;                          -> A string to be shown, %P% is replaced with Percentage
; Requirement(s):  This UDf
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSetFont()
; Description::    Sets the Font and Color of the Text of the Progressbar
; Parameter(s):    $ID : ID of Progressbar
;                  $Font      : Name of the font (empty String "" to do not change)
;                  $size      : [Optional] size of the font ( 0 or negative to leave the old)
;                  $Styles    : [Optional] The style of the typeface. Can be a combination of the following:
;                                  0 - Normal weight or thickness of the typeface
;                                  1 - Bold typeface
;                                  2 - Italic typeface
;                                  4 - Underline
;                                  8 - Strikethrough
;                                  ( -1, negative to leave the old)
;                  $ARGBcolor : [Optional] the color of the font, can be RGB or ARGB (depending on  $isARGB)
;                                  (empty String "" to do not change)
;                  $isARGB    : [Optional] Sets, whether $ARGBcolor is RGB (False, default) or ARGB (True)
; Requirement(s):  This UDF
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressSet()
; Description::    Sets the percentage of the Progressbar
; Parameter(s):    $ID : ID of Progressbar
;                  $prc The percentage to set
; Requirement(s):  This UDF :)
; Return Value(s): If Progressbar odes not Exist: @error is set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
;===============================================================================
;
; Function Name:   _ProgressMarquee()
; Description::    Sets the 
; Parameter(s):    $ID : ID of Progressbar
;                  $speed : The speed of the Marquee: 1 to 10, smaller as 1 turns it off
;                  $makeSmallFront : Crop the Front image to 1/10 of its former width
;                         If it was created by _ProgressSetColors, this is 1/10 of Progress Width :)
;                         If this is set to -1 and $speed is set to < 0 then the Front image size is 
;                             set to the width of the Progressbar
; Requirement(s):  WinAPI
; Return Value(s): If Progressbar does not Exist: @error is set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;

And an example:

#include <GDIpProgress.au3>
;##################################
; EXAMPLE
#Region EXAMPLE

$Gui = GUICreate("Gradient ProgressBar", 400, 350)

;Progress 1 + Controls
$slid = GUICtrlCreateSlider(5, 20, 310, 30) ;; check only for first bar
$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)
$btn_0 = GUICtrlCreateButton("0", 2, 100, 15, 25, 0)
$btn_25 = GUICtrlCreateButton("25", 20, 100, 75, 25, 0)
$btn_50 = GUICtrlCreateButton("50", 120, 100, 75, 25, 0)
$btn_75 = GUICtrlCreateButton("75", 220, 100, 75, 25, 0)
$btn_cl1 = GUICtrlCreateButton("Colors 1", 20, 140, 75, 25, 0)
$btn_cl2 = GUICtrlCreateButton("Colors 2", 220, 140, 75, 25, 0)
$btn_vistOK = GUICtrlCreateButton("Vista OK", 220, 180, 75, 25, 0)
$btn_vistError = GUICtrlCreateButton("Vista Error", 220, 210, 75, 25, 0)
$btn_vistPause = GUICtrlCreateButton("Vista Pause", 220, 240, 75, 25, 0)
$btn_txt = GUICtrlCreateButton("Set Text", 100, 180, 75, 25, 0)
$in_txt = GUICtrlCreateInput("%P%", 20, 180, 75, 25, 0)
GUICtrlSetTip(-1, "Use %P% to show Percentage" & @CRLF & "Leave empty to show no text")
$sID = _ProgressCreate(10, 60, 300, 40)
_ProgressSetText($sID, "Install %P%%")

; End Progress 1 + Controls

;Progress 2 + Controls
$Progress2 = _ProgressCreate(10, 280, 300, 20)
_ProgressSet($Progress2, 43)
$input = GUICtrlCreateInput("43", 320, 280, 50, 20, $ES_NUMBER)
GUICtrlSetLimit($input, 3, 1)
$updown = GUICtrlCreateUpdown($input)
GUICtrlSetLimit($updown, 100, 0)
;End Progress 2 + Controls

;Progress Marquee + Controls
$PMarquee = _ProgressCreate(10, 310, 300, 30)
_ProgressSetImages($PMarquee, @ScriptDir & "\prgimgs\marquee.jpg", @ScriptDir & "\prgimgs\bg.jpg")
_ProgressMarquee($PMarquee, 2, 0)
$marVist = GUICtrlCreateCheckbox("Vista Style",315,315,100,20)
GUICtrlSetState(-1,$GUI_CHECKED)
;End Progress Marquee + Controls

GUISetState()

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $btn_0
            _ProgressSet($sID, 0)
            GUICtrlSetData($slid, 0)
        Case $btn_25
            _ProgressSet($sID, 25)
            GUICtrlSetData($slid, 25)
        Case $btn_50
            _ProgressSet($sID, 50)
            GUICtrlSetData($slid, 50)
        Case $btn_75
            _ProgressSet($sID, 75)
            GUICtrlSetData($slid, 75)
            
        Case $btn_cl1
            _ProgressSetColors($sID, 0xFF0000, 0x00FF00, 0xA1B0BB, 0x4455FF)
            _ProgressSetFont($sID, "", -1, -1, 0xFFBBBBFF, True)
        Case $btn_cl2
            _ProgressSetColors($sID, 0x89A49B, 0xF0D6C7, 0xFFFFFF, 0xFFFFFF)
            _ProgressSetFont($sID, "", -1, -1, 0x000000)
        Case $btn_vistOK
            _ProgressSetImages($sID, @ScriptDir & "\prgimgs\green.jpg", @ScriptDir & "\prgimgs\bg.jpg")
            _ProgressSetFont($sID, "", -1, -1, 0x0000FF)
        Case $btn_vistPause
            _ProgressSetImages($sID, @ScriptDir & "\prgimgs\yellow.jpg", @ScriptDir & "\prgimgs\bg.jpg")
            _ProgressSetFont($sID, "", -1, -1, 0xFF0000)
        Case $btn_vistError
            _ProgressSetImages($sID, @ScriptDir & "\prgimgs\red.jpg", @ScriptDir & "\prgimgs\bg.jpg")
            _ProgressSetFont($sID, "", -1, -1, 0x000000)
            
        Case $btn_txt
            _ProgressSetText($sID, GUICtrlRead($in_txt))
        Case $input, $updown
            _ProgressSet($Progress2, GUICtrlRead($input))
            
        Case $marVist
            If BitAND(GUICtrlRead($marVist),$GUI_CHECKED) = $GUI_CHECKED Then
                _ProgressSetImages($PMarquee, @ScriptDir & "\prgimgs\marquee.jpg", @ScriptDir & "\prgimgs\bg.jpg")
            Else
                _ProgressSetColors($PMarquee, 0xFFFF00, 0x00FF00, 0xAAAA00, 0xFF0000)
                _ProgressMarquee($PMarquee, 2, 1)
            EndIf
            
        Case $GUI_EVENT_CLOSE
            _ProgressDelete($sID) ; MUST BE DONE ON EXIT
            _Progress_CallBack_Free(1) ; Force Killing Timer

            _GDIPlus_Shutdown()

            Exit
    EndSwitch

    If $iPercent <> GUICtrlRead($slid) Then
        $iPercent = GUICtrlRead($slid)
        GUICtrlSetData($Status_Label, $iPercent & "%")
        _ProgressSet($sID, $iPercent)
    EndIf


WEnd

Posted Image

Download-Link Downloads: Posted Image

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

Why delete you thread? For Scripts that have to work with older Windows without GDIplus, you can't use these UDFs :)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I got rid off some stuff and got this:

#include <GDIpProgress.au3>
;##################################
; EXAMPLE
#Region EXAMPLE

$Gui = GUICreate("Gradient ProgressBar", 400, 350)
$sID = _ProgressCreate(10, 60, 300, 20)
_ProgressSetText($sID, "%P%%")
_ProgressSetImages($sID, @ScriptDir & "\prgimgs\green.jpg", @ScriptDir & "\prgimgs\bg.jpg")
_ProgressSetFont($sID, "", -1, -1, 0x0000FF)
_ProgressSet($sID, 10)
GUISetState()

While 1
Tooltip($iPercent)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_ProgressDelete($sID); MUST BE DONE ON EXIT
_Progress_CallBack_Free(1); Force Killing Timer

_GDIPlus_Shutdown()

Exit
EndSwitch
WEnd

I thought that $iPercent whas the percent..

but it isn't how do I get the percent?? (like: GUICtrlRead($ProgressBar))

Link to comment
Share on other sites

To REad the Percent of a progressbar, use:

Func _ProgressGet(ByRef $ID)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or UBound($_Progress_Bars) < ($ID - 1) Then Return SetError(1, 0, 0)
        If _WinAPI_HiWord($_Progress_Bars[$ID][8]) > 0 Then Return -1; Marquee
    Return _WinAPI_LoWord($_Progress_Bars[$ID][8])
EndFunc

//Edit: The $iPercent is just a temporary variable to save the value of the slider and check it for changes :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 2 weeks later...

Very nice.

P.S if you set the bar to 0 then 1 a couple of times you will notice the end of the bar gets longer and shorter. Why is that?

[quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote]

Link to comment
Share on other sites

  • 2 weeks later...

This is awsome and perfect for a script i'm working on, but unfortunately it causes autoit to hang badly when OnEventMode is used and you try to close the window, exiting by using the tray icon works ok tho.

From what I can see the _ProgressDelete function isnt working, unless of course i'm just doing something dumb, any help appreciated muttley

This is not the actual script but a test representation that has the same result.

CODE
#include <GDIpProgress.au3>

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Opt("TrayIconDebug", 1)

#AutoIt3Wrapper_Run_Debug_Mode=Y

AutoItSetOption ( "TrayAutoPause", 0 )

$mainwindow = GUICreate("GDI test", 300, 300, -1, -1,$WS_OVERLAPPEDWINDOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Prog =_ProgressCreate(220,2, 70, 18)

_ProgressSetColors($Prog, 0xFFFF00, 0x00FF00, 0x0000FF, 0x000099)

_ProgressSetText ( $Prog, "")

_ProgressMarquee($Prog, 8, 0)

_ProgressMarquee($Prog, 8, 1)

GUISetState(@SW_SHOW)

While 1

Sleep(1000) ; Idle around

WEnd

Func _Exit()

_ProgressDelete($Prog)

_GDIPlus_Shutdown()

ConsoleWrite (@error)

Exit

EndFunc

Link to comment
Share on other sites

Error in error checking :) The Progressbar was never deleted and somehow, it got stuck then muttley

I reuploaded it, now it should work again.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

FIXED: Error in previous Fix. Variable used twice ...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Yeah, I was going to mention the error on exit but got side tracked with work, sorry.

One little thing, would it be possible to get it to obey the GUICtrlSetResizing (-1, $GUI_DOCKAUTO) command so it doesn't streeeetch with the window when it rezised ? Just a thought.

Link to comment
Share on other sites

  • 2 months later...

Bug for me.

I have make progress bar with example based.

When I click to my close button my Interface freeze.

In function _Progress_CallBack_Free,

before the call If $_Progress_ahCallBack[0] <> -1 Then DllCallbackFree($_Progress_ahCallBack[0])

I put a Msgbox(0,"test", "hello")

I run again my program and it close normaly.

When I comment these lines:

If $_Progress_ahCallBack[0] <> -1 Then DllCallbackFree($_Progress_ahCallBack[0])

If $_Progress_ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0*ConsoleWrite("KILL" & @CRLF) , "uint", $_Progress_ahCallBack[1])

Sometimes my App close normaly, sometimes it freeze.

If I call _GDIPlus_Shutdown() it's OK.

trace

$_Progress_ahCallBack[0]=1

An idea ?

Link to comment
Share on other sites

Bug for me.

I have make progress bar with example based.

When I click to my close button my Interface freeze.

In function _Progress_CallBack_Free,

before the call If $_Progress_ahCallBack[0] <> -1 Then DllCallbackFree($_Progress_ahCallBack[0])

I put a Msgbox(0,"test", "hello")

I run again my program and it close normaly.

When I comment these lines:

If $_Progress_ahCallBack[0] <> -1 Then DllCallbackFree($_Progress_ahCallBack[0])

If $_Progress_ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0*ConsoleWrite("KILL" & @CRLF) , "uint", $_Progress_ahCallBack[1])

Sometimes my App close normaly, sometimes it freeze.

If I call _GDIPlus_Shutdown() it's OK.

trace

$_Progress_ahCallBack[0]=1

An idea ?

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