Jump to content



Photo

Progressbar with GDIplus


  • Please log in to reply
54 replies to this topic

#1 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 26 June 2008 - 03:07 PM

This is a port of the example Script in How about a progressbar like this? to an UDF.
These are the functions:
AutoIt         
#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:
AutoIt         
#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, 03 May 2011 - 04:13 PM.

  • syk3s likes this
*GERMAN* Posted Image [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







#2 Uriziel01

Uriziel01

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 281 posts

Posted 26 June 2008 - 03:53 PM

WoW ! I like it very much ! :P I'll better delete thread with my "pseudo" ProgressBar UDF :P Very impressive :) Thx for Sharing
Posted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted Image

#3 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 26 June 2008 - 04:32 PM

Why delete you thread? For Scripts that have to work with older Windows without GDIplus, you can't use these UDFs :)
*GERMAN* Posted Image [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

#4 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 26 June 2008 - 04:36 PM

I Loooooooveeeeee it!!

#5 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 26 June 2008 - 05:01 PM

I got rid off some stuff and got this:
Plain Text         
#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))

#6 gseller

gseller

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,057 posts

Posted 26 June 2008 - 06:37 PM

Love It!! Great Work! :)

#7 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 26 June 2008 - 07:27 PM

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, 26 June 2008 - 07:29 PM.

*GERMAN* Posted Image [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

#8 JustinMeyer

JustinMeyer

    Wayfarer

  • Active Members
  • Pip
  • 67 posts

Posted 04 July 2008 - 09:39 PM

This is very very cool! Does anyone know of a well documented resource on GDI+, I have not had much luck with MSDN.
Mostly have had to rely on the forums (so helpful, thanks everyone) and trial and error.
Posted Image

#9 MerkurAlex

MerkurAlex

    I live on cookies and AutoIt.

  • Active Members
  • PipPipPipPipPipPip
  • 639 posts

Posted 05 July 2008 - 09:39 PM

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?

Larry is a mass murderer?! Posted ImageIt's always the quiet, clean cut, bald guys... Posted Image


#10 DK12000

DK12000

    Seeker

  • Active Members
  • 17 posts

Posted 19 July 2008 - 01:32 PM

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


#11 TehWhale

TehWhale

    Whalee..

  • Banned (NOT IN USE)
  • 1,482 posts

Posted 19 July 2008 - 02:20 PM

This is amazing! Except for the On-Event issue.

#12 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 19 July 2008 - 02:34 PM

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* Posted Image [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

#13 DK12000

DK12000

    Seeker

  • Active Members
  • 17 posts

Posted 20 July 2008 - 06:31 AM

Awsome, that fixed it. Thanks for this, it is now my progress bar of choice :muttley:
  • jmon likes this

#14 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 20 July 2008 - 02:39 PM

FIXED: Error in previous Fix. Variable used twice ...
*GERMAN* Posted Image [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

#15 TehWhale

TehWhale

    Whalee..

  • Banned (NOT IN USE)
  • 1,482 posts

Posted 20 July 2008 - 04:12 PM

Thanks, love it!

#16 Achilles

Achilles

    Achilles == Ichigo

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 21 July 2008 - 08:24 AM

Wow! Very nice work on this. I might change a few up my scripts to use it just so they look better..

#17 DK12000

DK12000

    Seeker

  • Active Members
  • 17 posts

Posted 23 July 2008 - 12:52 PM

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.

#18 Darth

Darth

    Wayfarer

  • Active Members
  • Pip
  • 66 posts

Posted 23 July 2008 - 08:42 PM

thanks this'll be great for my battle system once I get around to recoding it

#19 dmoniac

dmoniac

    Seeker

  • Active Members
  • 21 posts

Posted 06 October 2008 - 09:58 AM

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 ?

#20 dmoniac

dmoniac

    Seeker

  • Active Members
  • 21 posts

Posted 06 October 2008 - 09:58 AM

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 ?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users