Sign in to follow this  
Followers 0
RobertKipling

How about a progressbar like this?

24 posts in this topic

post-27982-1203539836_thumb.jpg

I know everyone says it can't be done, but GimpPortable proves that it can. The statusbar also themes depending on whether you're running Windows XP under standard or Royale themes.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

post-27982-1203539836_thumb.jpg

I know everyone says it can't be done, but GimpPortable proves that it can. The statusbar also themes depending on whether you're running Windows XP under standard or Royale themes.

Here is an easier way perhaps

#include <GUIConstants.au3>

$gui = GUICreate("My GUI"); will create a dialog box that when displayed is centered
$pic = guictrlcreatepic("gradientbar.bmp",20,50,5,15)
GUISetState (@SW_SHOW) 
for $n = 1 to 200
    ControlMove($gui,"",$pic,20,50,5 + $n,15)
    sleep(20)
Next

while guigetmsg() <> -3
    
    WEnd

EDIT: corrected attachment to be the bitmap, it was the script by mistake.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hi martin,

Nice idea, but not working as i expected, the image (i made one simple) is like stretched.

Here is an example with label moving (the picure is on place always)..

#include <GUIConstants.au3>

$Gradient_Progress_Bar_Img = @ScriptDir & "\Gradient_Progress_Bar.bmp"

If Not FileExists($Gradient_Progress_Bar_Img) Then _
    InetGet("http://creator-lab.ucoz.ru/Images/Gradient_Progress_Bar.bmp", $Gradient_Progress_Bar_Img)

$Gui = GUICreate("Gradient Progress Bar", 340, 100)
GUISetBkColor(0xC0C0C0)

GUICtrlCreateLabel("Progress Bar", 20, 15, 300, 15)
GUICtrlCreatePic($Gradient_Progress_Bar_Img, 20, 30, 300, 15, $SS_SUNKEN)

$Cover_Label = GUICtrlCreateLabel("", 20, 30, 300, 15, $SS_SUNKEN)

$Go_Button = GUICtrlCreateButton("GO!", 20, 70, 40, 20)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go_Button
            GUICtrlSetData($Go_Button, "Abort!")
            
            For $i = 15 To 315
                ControlMove($Gui, "", $Cover_Label, $i + 5, 30, 315 - $i, 15)
                
                $nMsg = GUIGetMsg()
                
                If $nMsg = $Go_Button Then
                    ControlMove($Gui, "", $Cover_Label, 20, 30, 300, 15)
                    ExitLoop
                EndIf
                
                If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop 2
                
                Sleep(20)
            Next
            
            GUICtrlSetData($Go_Button, "GO!")
    EndSwitch
WEnd

And the image.

BTW: If there is no image (i only now seen that you attached the image :) ), ControlMove moving the Gui itself.. strange...


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Hi martin,

Nice idea, but not working as i expected, the image (i made one simple) is like stretched.

Here is an example with label moving (the picure is on place always)..

#include <GUIConstants.au3>

$Gradient_Progress_Bar_Img = @ScriptDir & "\Gradient_Progress_Bar.bmp"

If Not FileExists($Gradient_Progress_Bar_Img) Then _
    InetGet("http://creator-lab.ucoz.ru/Images/Gradient_Progress_Bar.bmp", $Gradient_Progress_Bar_Img)

$Gui = GUICreate("Gradient Progress Bar", 340, 100)
GUISetBkColor(0xC0C0C0)

GUICtrlCreateLabel("Progress Bar", 20, 15, 300, 15)
GUICtrlCreatePic($Gradient_Progress_Bar_Img, 20, 30, 300, 15, $SS_SUNKEN)

$Cover_Label = GUICtrlCreateLabel("", 20, 30, 300, 15, $SS_SUNKEN)

$Go_Button = GUICtrlCreateButton("GO!", 20, 70, 40, 20)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Go_Button
            GUICtrlSetData($Go_Button, "Abort!")
            
            For $i = 15 To 315
                ControlMove($Gui, "", $Cover_Label, $i + 5, 30, 315 - $i, 15)
                
                $nMsg = GUIGetMsg()
                
                If $nMsg = $Go_Button Then
                    ControlMove($Gui, "", $Cover_Label, 20, 30, 300, 15)
                    ExitLoop
                EndIf
                
                If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop 2
                
                Sleep(20)
            Next
            
            GUICtrlSetData($Go_Button, "GO!")
    EndSwitch
WEnd

And the image.

BTW: If there is no image (i only now seen that you attached the image :) ), ControlMove moving the Gui itself.. strange...

That's a nice effect in your example MsCreatoR.

If you use the image I attached then you shouldn't have a problem with 'stretch'.

I tried it without a pic and you are right, a strange effect. If the file isn't found then the ID of the pic remains at 0. If you put Zero there then the same thing happens. Still, very strange because it's only supposed to move controls within windows, but in this situation it behaves like WinMove.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

i know this probably isnt useful, but i made something pretty. see attached

Yes that's a good idea. By changing the style and colour of the label you can get different effects. I like this one

$picbk = guictrlcreateLabel("",19,49,208,19,BitOr($SS_SUNKEN ,$SS_ETCHEDFRAME))

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Here is a _GDIPlus... full usage :) (originaly by Diamond) :

#include <GuiConstants.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

Global $ahCallBack[2], $iPrecent

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

GUICtrlCreateLabel("", 9, 9, 302, 22, -1, $WS_EX_STATICEDGE)
GUICtrlCreateLabel("", 9, 39, 302, 22, -1, $WS_EX_STATICEDGE)

GUICtrlCreateLabel("There is  few more colors commented in the script bellow...", 10, 200)

$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)

$Button = GUICtrlCreateButton("Start",150,100,50,20)

_GDIPlus_Startup()

$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($Gui)

$hBitMap = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)

$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap)

$hPen = _GDIPlus_PenCreate(0,1)

$Depth = 1.64 ; Min = 1.10  Max = 1.70

For $i = 1 To 20
;~  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Orange
;~  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(200 - $i^$Depth), 2) & "FF" ; Magenta
;~  $PenColor = "0xFF" & Hex(80  + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Green
    $PenColor = "0xFF" & Hex(80  + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "FF" ; Blue
    _GDIPlus_PenSetColor($hPen, $PenColor)
    _GDIPlus_GraphicsDrawLine($hGraphic2, 0, $i-1, 300, $i-1, $hPen)
Next

_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic2)


$hBitMap_Multiply = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap_Multiply)

For $i = 0 To 15 Step 5 
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic2, $hBitMap, 0, 0, 300, 20, 0, $i, 300, 5)
Next

_GDIPlus_GraphicsDispose($hGraphic2)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button
            If $iPrecent = 0 Then _WinAPI_RedrawWindow($Gui)
            
            If GUICtrlRead($Button) = "Stop" Then
                GUICtrlSetData($Button, "Start")
                CallBack_Free($ahCallBack)
                
                ContinueLoop
            EndIf
            
            GUICtrlSetData($Button, "Stop")
            
            $ahCallBack = CallBack_Init("Paint_Proc", 10)
        Case $GUI_EVENT_CLOSE
            CallBack_Free($ahCallBack)
            
            _GDIPlus_ImageDispose($hBitmap)
            _GDIPlus_ImageDispose($hBitMap_Multiply)
            _GDIPlus_GraphicsDispose($hGraphic1)
            _GDIPlus_Shutdown()
            
            Exit
    EndSwitch
WEnd

Func Paint_Proc($hWnd, $nMsg, $wParam, $lParam)
    $iPrecent += 1
    
    GUICtrlSetData($Status_Label, Round($iPrecent / 3) & "%")
    
    If $iPrecent > 300 Then
        $iPrecent = 0
        
        GUICtrlSetData($Status_Label, "100%")
        GUICtrlSetData($Button, "Start")
        CallBack_Free($ahCallBack)
        
        $ahCallBack = 0
        Dim $ahCallBack[2] = [-1, -1]
    EndIf
    
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap, 0, 0, $iPrecent, 20, 10, 10, $iPrecent, 20)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap_Multiply, 0, 0, $iPrecent, 20, 10, 40, $iPrecent, 20)
EndFunc

Func CallBack_Init($sFuncName, $iTime, $sParam = "hwnd;int;int;dword")
    Local $hCallBack = DLLCallbackRegister($sFuncName, "int", $sParam)
    
    Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _
        "hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr($hCallBack))
    
    Local $ahCallBack[2] = [$hCallBack, $aTimer[0]]
    
    Return $ahCallBack
EndFunc

Func CallBack_Free($ahCallBack)
    If $ahCallBack[0] <> -1 Then DllCallbackFree($ahCallBack[0])
    If $ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $ahCallBack[1])
EndFunc

If you use the image I attached then you shouldn't have a problem with 'stretch'.

Yes, that's much better now! ;) Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Yes that's a good idea. By changing the style and colour of the label you can get different effects. I like this one

$picbk = guictrlcreateLabel("",19,49,208,19,BitOr($SS_SUNKEN ,$SS_ETCHEDFRAME))
the cool thing about using a label is you can add custom load text that becomes hidden as the load bar fills. for example

$picbk = guictrlcreateLabel("                YOUR FILE IS LOADERIZING!",20,50,205,15)

Share this post


Link to post
Share on other sites

Here is a _GDIPlus... full usage :) (originaly by Diamond) :

#include <GuiConstants.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

Global $ahCallBack[2], $iPrecent

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

GUICtrlCreateLabel("", 9, 9, 302, 22, -1, $WS_EX_STATICEDGE)
GUICtrlCreateLabel("", 9, 39, 302, 22, -1, $WS_EX_STATICEDGE)

GUICtrlCreateLabel("There is  few more colors commented in the script bellow...", 10, 200)

$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)

$Button = GUICtrlCreateButton("Start",150,100,50,20)

_GDIPlus_Startup()

$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND($Gui)

$hBitMap = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)

$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap)

$hPen = _GDIPlus_PenCreate(0,1)

$Depth = 1.64 ; Min = 1.10  Max = 1.70

For $i = 1 To 20
;~  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Оранжевый
;~  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(200 - $i^$Depth), 2) & "FF" ; Пурпурный
;~  $PenColor = "0xFF" & Hex(80  + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Зелёный
    $PenColor = "0xFF" & Hex(80  + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "FF" ; Голубой
    _GDIPlus_PenSetColor($hPen, $PenColor)
    _GDIPlus_GraphicsDrawLine($hGraphic2, 0, $i-1, 300, $i-1, $hPen)
Next

_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic2)


$hBitMap_Multiply = _GDIPlus_BitmapCreateFromGraphics(300, 20, $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hBitMap_Multiply)

For $i = 0 To 15 Step 5 
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic2, $hBitMap, 0, 0, 300, 20, 0, $i, 300, 5)
Next

_GDIPlus_GraphicsDispose($hGraphic2)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button
            If $iPrecent = 0 Then _WinAPI_RedrawWindow($Gui)
            
            If GUICtrlRead($Button) = "Stop" Then
                GUICtrlSetData($Button, "Start")
                CallBack_Free($ahCallBack)
                
                ContinueLoop
            EndIf
            
            GUICtrlSetData($Button, "Stop")
            
            $ahCallBack = CallBack_Init("Paint_Proc", 10)
        Case $GUI_EVENT_CLOSE
            CallBack_Free($ahCallBack)
            
            _GDIPlus_ImageDispose($hBitmap)
            _GDIPlus_ImageDispose($hBitMap_Multiply)
            _GDIPlus_GraphicsDispose($hGraphic1)
            _GDIPlus_Shutdown()
            
            Exit
    EndSwitch
WEnd

Func Paint_Proc($hWnd, $nMsg, $wParam, $lParam)
    $iPrecent += 1
    
    GUICtrlSetData($Status_Label, Round($iPrecent / 3) & "%")
    
    If $iPrecent > 300 Then
        $iPrecent = 0
        
        GUICtrlSetData($Status_Label, "100%")
        GUICtrlSetData($Button, "Start")
        CallBack_Free($ahCallBack)
        
        $ahCallBack = 0
        Dim $ahCallBack[2] = [-1, -1]
    EndIf
    
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap, 0, 0, $iPrecent, 20, 10, 10, $iPrecent, 20)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic1, $hBitMap_Multiply, 0, 0, $iPrecent, 20, 10, 40, $iPrecent, 20)
EndFunc

Func CallBack_Init($sFuncName, $iTime, $sParam = "hwnd;int;int;dword")
    Local $hCallBack = DLLCallbackRegister($sFuncName, "int", $sParam)
    
    Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _
        "hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr($hCallBack))
    
    Local $ahCallBack[2] = [$hCallBack, $aTimer[0]]
    
    Return $ahCallBack
EndFunc

Func CallBack_Free($ahCallBack)
    If $ahCallBack[0] <> -1 Then DllCallbackFree($ahCallBack[0])
    If $ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $ahCallBack[1])
EndFunc

Yes, that's much better now! ;)

That's great! I'll keep that one, thanks MsCreatoR.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Same thing here... I might consider using this in my Multiple Desktops instead of the standard GuiCtrlCreateProgress..

Just remember that it is using _GDIPlus_GraphicsDrawxxxxxxx which means if the window is min. or another window placed in front of it your image goes away.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Yes, that's much better now!

Nice example, but is need a little checking. If i`m run this script and immediately close, then are getting this error:

Posted Image

Just need little correction here:

Case $GUI_EVENT_CLOSE
    If $ahCallBack Then CallBack_Free($ahCallBack)
:)

Share this post


Link to post
Share on other sites

THX ALL ! Nice scripts :)

I like them ...

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Then there's this that's by Dhillip89 http://www.autoitscript.com/forum/index.ph...st&p=258803

The links in his post are no good anymore, but I downloaded it before.

He even started to make a UDF out of it which is also included

Edit: fixed link to thread

PicProgressBar_Experimental_.zip

Edited by ResNullius

Share this post


Link to post
Share on other sites

Then there's this that's by Dhillip89 http://www.autoitscript.com/forum/index.ph...st&p=258803

The links in his post are no good anymore, but I downloaded it before.

He even started to make a UDF out of it which is also included

Edit: fixed link to thread

It's not updated to latest beta but once the necessary includes are there it works really nice...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

hi all

i like the colored progress bar

does anyone know how i could add mouse support ? i would like to "move " the progress bar with the mouse - or get position of mouse within progress bar

tnx

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

hi

ok i changed some of the code

now i can move the bar with the mouse and have a dynamic control width

i still couldnt figure out how i can void the flickering - if i move from left -> right its fine . but from right - left i need to invalidate to redraw which results in flickering..

nobbe

#include <GuiConstants.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

;
Opt("MouseCoordMode", 2)

Global $user32_dll = DllOpen("user32.dll"); for mouse
Global $ahCallBack[2], $iPercent, $i_oldPercent

;; global for bar position
Global $bar_start_x = 10;
Global $bar_start_y = 10;
Global $bar_width = 300;
Global $bar_height = 20;
;Global Const $tagRECT = "int Left;int Top;int Right;int Bottom"

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

$bar1 = GUICtrlCreateLabel("", $bar_start_x, $bar_start_y, $bar_width, $bar_height, -1, $WS_EX_STATICEDGE) ;; check only for first bar
;GUICtrlCreateLabel("", 10, 40, $bar_width, $bar_height, -1, $WS_EX_STATICEDGE)

$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)
$Button = GUICtrlCreateButton("Start", 150, 100, 50, 20)

_GDIPlus_Startup ()

$hGraphic1 = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hBitMap = _GDIPlus_BitmapCreateFromGraphics ($bar_width, 20, $hGraphic1)

$hGraphic2 = _GDIPlus_ImageGetGraphicsContext ($hBitMap)

$hPen = _GDIPlus_PenCreate (0, 1)

$Depth = 1.70 ; Min = 1.10  Max = 1.70

For $i = 1 To 20
  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Orange
  $PenColor = "0xFF" & Hex(255 - $i, 2) & Hex(Round(200 - $i^$Depth), 2) & "FF" ; Magenta
;  $PenColor = "0xFF" & Hex(80  + $i, 2) & Hex(Round(240 - $i^$Depth), 2) & "3B" ; Green
    $PenColor = "0xFF" & Hex(80 + $i, 2) & Hex(Round(240 - $i ^ $Depth), 2) & "FF" ; Blue

    _GDIPlus_PenSetColor ($hPen, $PenColor)
    _GDIPlus_GraphicsDrawLine ($hGraphic2, 0, $i - 1, $bar_width, $i - 1, $hPen)
Next
_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic2)



#cs
$hBitMap_Multiply = _GDIPlus_BitmapCreateFromGraphics ($bar_width, $bar_height, $hGraphic1)

$hGraphic2 = _GDIPlus_ImageGetGraphicsContext ($hBitMap_Multiply)

For $i = 0 To 15 Step 5
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic2, $hBitMap, 0, 0, $bar_width, $bar_height, 0, $i, $bar_width, 5)
Next

_GDIPlus_GraphicsDispose ($hGraphic2)
#ce



GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button
            
            If $iPercent = 0 Then _WinAPI_RedrawWindow ($Gui)

            If GUICtrlRead($Button) = "Stop" Then
                GUICtrlSetData($Button, "Start")
                CallBack_Free($ahCallBack)

                ContinueLoop
            EndIf

            GUICtrlSetData($Button, "Stop")


            
            ;; was
            $ahCallBack = CallBack_Init("Paint_Proc1", 30) ;; was Paint_Proc
            
        Case $GUI_EVENT_CLOSE
            CallBack_Free($ahCallBack)

            _GDIPlus_ImageDispose ($hBitMap)
;           _GDIPlus_ImageDispose ($hBitMap_Multiply)

            _GDIPlus_GraphicsDispose ($hGraphic1)
            _GDIPlus_Shutdown ()

            Exit
    EndSwitch
    
    
    ;; my mouse BTN is down --
    
    If _IsPressed("01", $user32_dll) Then
        While _IsPressed("01", $user32_dll)
            
            $pos = MouseGetPos()
            If ($pos[0] >= $bar_start_x) And ($pos[0] <= ($bar_width + $bar_start_x)) And _
                    ($pos[1] >= $bar_start_y) And ($pos[1] <= ($bar_height + $bar_start_y)) Then  ;; are we within bar ??

                ; _WinAPI_RedrawWindow ($Gui)
                
                $iPercent = Int(($pos[0] - $bar_start_x) / $bar_width * 100);
                
                ;$position_in_bar = $bar_width / 100 * $iPercent
                _DebugPrint("Mouse is x,y:" & $pos[0] & "," & $pos[1] & " percent : " & $iPercent);

            EndIf

        WEnd
    EndIf ; mouse BTN 1 pressed??

WEnd



;; other function now 
Func Paint_Proc1($hWnd, $nMsg, $wParam, $lParam)

    ; sb_width== 100%

    GUICtrlSetData($Status_Label, $iPercent & "%")
    $position_in_bar = $bar_width / 100 * $iPercent

    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic1, $hBitMap, 0, 0, $iPercent, $bar_height, $bar_start_x, $bar_start_y, $position_in_bar, $bar_height)

    ;; we move Backwards ? then refresh screen or it wont update - unfortunately flickers like .....
    
    If ($i_oldPercent > $iPercent) Then
;       SetItemRect($tagRECT, $bar_start_x, $bar_start_x + $bar_width,$bar_start_y , $bar_start_y + $bar_height)
#cs
        $tagRECT.Left= $bar_start_x
        $tagRECT.Right= $bar_start_x + $bar_width
        
        $tagRECT.Bottom= $bar_start_y 
        $tagRECT.Top= $bar_start_y + $bar_height
    #ce 

; hm , how to do this ?? 
;       _WinAPI_RedrawWindow ($Gui, $tagRECT); hm..
        _WinAPI_RedrawWindow ($Gui); hm..
    EndIf

    $i_oldPercent = $iPercent;
    
EndFunc   ;==>Paint_Proc1


Func CallBack_Init($sFuncName, $iTime, $sParam = "hwnd;int;int;dword")
    Local $hCallBack = DLLCallbackRegister ($sFuncName, "int", $sParam)

    Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _
            "hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr ($hCallBack))

    Local $ahCallBack[2] = [$hCallBack, $aTimer[0]]

    Return $ahCallBack
EndFunc   ;==>CallBack_Init


;
;
Func CallBack_Free($ahCallBack)
    If $ahCallBack[0] <> -1 Then DllCallbackFree ($ahCallBack[0])
    If $ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $ahCallBack[1])
EndFunc   ;==>CallBack_Free


;
;
;
Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-")
    ConsoleWrite($s_text & @LF); & _
EndFunc   ;==>_DebugPrint

;
#cs
Func SetItemRect(ByRef $stStruct, $p1, $p2, $p3, $p4)
    DllStructSetData($stStruct, 1, $p1)
    DllStructSetData($stStruct, 2, $p2)
    DllStructSetData($stStruct, 3, $p3)
    DllStructSetData($stStruct, 4, $p4)
EndFunc

#ce

Share this post


Link to post
Share on other sites

Thank you very much for the code, but I am still convinced that there is a way to use a Windows progressbar without creating one from scratch. The one I showed was from GIMP, which skinned properly in Windows XP running regular, Royale, and Royale Vista themes.

Share this post


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
Sign in to follow this  
Followers 0