Jump to content
Sign in to follow this  
RobertKipling

How about a progressbar like this?

Recommended Posts

hi

i figured it out now

;
; a gradient bar with mouse control
;
; draw a bar on the dialog , move mouse in bar to get percentage of bar
;
; or set bar position manually with button control 
;
;
; by nobbe 2008 


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

; for mouse coord on control
Opt("MouseCoordMode", 2)

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

;; global for bar position
Global $bar_start_x = 10;
Global $bar_start_y = 10;
Global $bar_width = 300;
Global $bar_height = 20;

Global $framewidth = 2 ; 2 pixel are black & white frame from control

;; ------- GUI

$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
$Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)

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


;;; ---- GDI

_GDIPlus_Startup ()

;; create blue color Bar

$hGraphic_bar_left_side = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hBitMap_bar_left_side = _GDIPlus_BitmapCreateFromGraphics ($bar_width, 20, $hGraphic_bar_left_side)
$hGraphic_tmp1 = _GDIPlus_ImageGetGraphicsContext ($hBitMap_bar_left_side)
$hPen = _GDIPlus_PenCreate (0, 1)
$Depth = 1.4 ; 1.70 ; Min = 1.10  Max = 1.70

For $i = 1 To $bar_height
    ;  $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

    ;; alpha / r,g,b

    $PenColor = "0xFF" & Hex(10 + $i, 2) & Hex(Round(80 - $i ^ $Depth), 2) & "FF" ; Blue
    _GDIPlus_PenSetColor ($hPen, $PenColor)
    _GDIPlus_GraphicsDrawLine ($hGraphic_tmp1, 0, $i - 1, $bar_width, $i - 1, $hPen)
Next

_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic_tmp1)


;; create grey color Bar  on the right side

$hGraphic_bar_right_side = _GDIPlus_GraphicsCreateFromHWND ($Gui)
$hBitMap_bar_right_side = _GDIPlus_BitmapCreateFromGraphics ($bar_width, 20, $hGraphic_bar_right_side)
$hGraphic_tmp2 = _GDIPlus_ImageGetGraphicsContext ($hBitMap_bar_right_side)
$hPen = _GDIPlus_PenCreate (0, 1)
;; flat now
For $i = 1 To $bar_height
    $PenColor = "0xFFE0DFE3" ; some grey
    _GDIPlus_PenSetColor ($hPen, $PenColor)
    _GDIPlus_GraphicsDrawLine ($hGraphic_tmp2, 0, $i - 1, $bar_width, $i - 1, $hPen)
Next

_GDIPlus_PenDispose ($hPen)
_GDIPlus_GraphicsDispose ($hGraphic_tmp2)

;; -- vs NOD ----------------------

;; start call back now
$ahCallBack = CallBack_Init("Paint_Bar_Procedure", 200) ;; with millisec timer

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg


        Case $btn_25
            _move_bar(25);
        Case $btn_50
            _move_bar(50);
        Case $btn_75
            _move_bar(75);


        Case $GUI_EVENT_CLOSE
            CallBack_Free($ahCallBack)

            _GDIPlus_ImageDispose ($hBitMap_bar_left_side)
            _GDIPlus_GraphicsDispose ($hGraphic_bar_left_side)
            
            _GDIPlus_ImageDispose ($hBitMap_bar_right_side)
            _GDIPlus_GraphicsDispose ($hGraphic_bar_right_side)

            _GDIPlus_Shutdown ()

            Exit
    EndSwitch
    



    ;; my mouse BTN LEFT is down --
    
    If _IsPressed("01", $user32_dll) Then
        While _IsPressed("01", $user32_dll)
            
            $pos = MouseGetPos()
            
            $pos[0] += $framewidth; add frame with of control
            
            
            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 ??
                
                $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_Bar_Procedure($hWnd, $nMsg, $wParam, $lParam)

; move the bar 
    _move_bar($iPercent);
EndFunc   ;==>Paint_Bar_Procedure

; 

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


;
; draws 2 bars , left is blue , right is grey 
; 
FUNC _move_bar($prc)

    $iPercent = $prc 

    GUICtrlSetData($Status_Label, $prc & "%")
    $position_in_bar = $bar_width / 100 * $prc - ($framewidth * 2) ;; or we move out the bar

    ;; draw blue bar from left
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic_bar_left_side, $hBitMap_bar_left_side, _
            0, 0, $prc, $bar_height, _
            $bar_start_x + $framewidth, _
            $bar_start_y + $framewidth, _
            $position_in_bar, _
            $bar_height - ($framewidth * 2))

    ; draw grey bar to right side
    _GDIPlus_GraphicsDrawImageRectRect ($hGraphic_bar_right_side, $hBitMap_bar_right_side, 0, 0, $prc, $bar_height, _
            ($position_in_bar + $bar_start_x) + $framewidth, _
            $bar_start_y + $framewidth, _
            $bar_width - $position_in_bar - ($framewidth * 2), _
            $bar_height - $framewidth * 2);
endfunc

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

Thanx for sharing it, ResNullius. :)

I have played with it and the result is this ...

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=progressEx.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 1.bmp, bitmap, 1, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 2.bmp, bitmap, 2, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 3.bmp, bitmap, 3, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 4.bmp, bitmap, 4, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 5.bmp, bitmap, 5, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 6.bmp, bitmap, 6, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\Aut2Exe\upx.exe --best --compress-resources=1 "%out%"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;========================================================================================
;
;                                   ProgressBar.au3
;
;       Create Progressbar with Bitmaps.
;
;       Author: Greenhorn
;
;
;========================================================================================
#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Opt('OnExitFunc', 'Terminate')

Global Const $NULL = Ptr(0)
Global Const $SS_CENTER = 1
Global Const $SS_NOTIFY = 0x0100
Global Const $LR_LOADFROMFILE = 16
Global Const $STM_SETIMAGE = 0x0172
Global Const $IMAGE_BITMAP = 0
Global $gdi32dll    = DllOpen('gdi32.dll')
Global $user32dll   = DllOpen('user32.dll')
Global $kernel32dll = DllOpen('kernel32.dll')
Global $hBitmap[7]

$hInst = GetModuleHandle()

; Bitmaps laden.
For $i = 1 To 6
    
    ; to work with resources use LoadImage like in the line below
    ; and correct the pathes in #AutoIt3Wrapper_Run_After.
;   $hBitmap[$i] = LoadImage($hInst, $i, $IMAGE_BITMAP)

    ; to work with Bitmaps on Harddisk take this line
    $hBitmap[$i] = LoadImage($NULL, String($i) & '.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
    
Next


; Testfenster erstellen.
$hWnd = GUICreate('ProgressBar mit Bitmaps - Demo', 500, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
GUISetBkColor(0xFFFFFF)
GUISetFont(10, 800, 0, 'SegoeUI')

GUICtrlCreateLabel('Progressbar Test', 0, 80, 500, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont(-1, 12, 800, 0, 'SegoeUI')

$aProgressBar1 = ProgressBarCreate(100, 150, 300, $hWnd)

ProgressBarSetState($aProgressBar1)
GUISetState(@SW_SHOW, $hWnd)

$aProgressBar2 = ProgressBarCreate(100, 150, 500)
ProgressBarSetState($aProgressBar2)

Sleep(1500)
TestProgress($aProgressBar1)
TestProgress($aProgressBar2)

;Sleep(1500)
;ProgressBarDelete($aProgressBar1)
;ProgressBarDelete($aProgressBar2)

While True
    
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
    
WEnd

Func TestProgress($aProgress)
    
    For $i = 1 To 100
        ProgressBarSetData($aProgress, $i)
        Sleep(20)
    Next
    
EndFunc

Func ProgressBarCreate($x, $y, $iWidth, $hWndParent = 0)
    
    Local $dwExStyleCtrl, $aProgress[2][$iWidth + 1]
    $aProgress[1][0] = $iWidth
    
    If Not $hWndParent Or $hWndParent = 0 Then
        $aProgress[0][0] = GUICreate('ProgressBar', $iWidth, 15, $x, $y, BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), $WS_EX_LAYERED)
        $dwExStyleCtrl = BitOr($WS_EX_LAYERED,$GUI_WS_EX_PARENTDRAG)
    Else
        $aProgress[0][0] = GUICreate('ProgressBar', $iWidth, 15, $x, $y, BitOR($WS_DISABLED, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), BitOr($WS_EX_LAYERED, $WS_EX_MDICHILD), $hWndParent)
    EndIf
    
    $aProgress[1][1] = GUICtrlCreatePic('', 0, 0, 2, 15, BitOR($WS_CLIPSIBLINGS, $SS_NOTIFY,$WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][1], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[1])
    
    For $i = 2 To $iWidth - 2
        $aProgress[1][$i] = GUICtrlCreatePic('', $i, 0, 1, 15, BitOR($WS_CLIPSIBLINGS, $SS_NOTIFY, $WS_CHILD), $dwExStyleCtrl)
        GUICtrlSetState(-1, $GUI_ONTOP)
        GUICtrlSendMsg($aProgress[1][$i], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[3])
    Next
    
    $aProgress[1][$iWidth] = GUICtrlCreatePic('', $iWidth - 2, 0, 2, 15, BitOR($WS_CLIPSIBLINGS, $SS_NOTIFY,$WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][$iWidth], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[2])
    
    $aProgress[0][1] = GUICtrlCreateLabel('', ($iWidth / 2) -15, 0, 40, 15, BitOR($SS_CENTER , $WS_CHILD), $dwExStyleCtrl)
    GUICtrlSetColor(-1,0x424242)
    GUICtrlSetFont(-1, 8.5, 800, 0, 'SegoeUI')
    If Not $hWndParent Then GUICtrlSetTip(-1, "Drag me, please ... ;) ")
    
    Return $aProgress
    
EndFunc

Func ProgressBarSetData($aProgress, $iPercent)
    
    $iSize = ($aProgress[1][0] / 100)
    $cxEnd = $iSize * $iPercent
    $cxStart = $cxEnd - ($iSize)
    
    ProgressBarSetText($aProgress, $iPercent & ' %')
    
    For $i = Int($cxStart) To Int($cxEnd)
        If $i = 1 Then
            GUICtrlSendMsg($aProgress[1][1], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[5])
        ElseIf $iPercent = 100 And $i = Int($cxEnd) Then
            GUICtrlSendMsg($aProgress[1][$aProgress[1][0]], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[6])
        Else
            GUICtrlSendMsg($aProgress[1][$i], $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap[4])
        EndIf
    Next
    
EndFunc

Func ProgressBarSetState($aProgress, $State = @SW_SHOW)
    
    GUISetState($State, $aProgress[0][0])
    
    GUICtrlSetBkColor($aProgress[0][1], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetData($aProgress[0][1], '0 %')
    GUICtrlSetState($aProgress[0][1], $GUI_ONTOP)
    
EndFunc

Func ProgressBarDelete($aProgress)
    
    If $aProgress[0][0] Then
        GUIDelete($aProgress[0][0])
    Else
        For $i = 1 To $aProgress[1][0]
            GUICtrlSendMsg($aProgress[1][$i], $WM_CLOSE, 0, 0)
        Next
    EndIf
    
EndFunc

Func ProgressBarSetText($aProgress, $sText)
    
    GUICtrlSetState($aProgress[0][1], $GUI_HIDE)
    GUICtrlSetData($aProgress[0][1], $sText)
    GUICtrlSetState($aProgress[0][1], $GUI_SHOW)
    GUICtrlSetState($aProgress[0][1], $GUI_ONTOP)

EndFunc

Func LoadImage($hInstance, $lpszName, $uType, $cxDesired = 0, $cyDesired = 0, $fuLoad = 0)
    
    If IsNumber($lpszName) Then $lpszName = MAKEINTRESOURCE($lpszName)
    Local $aResult = DllCall($user32dll, 'hwnd', 'LoadImage', _
                                                    'ptr',  $hInstance, _
                                                    'str',  $lpszName, _
                                                    'uint', $uType, _
                                                    'int',  $cxDesired, _
                                                    'int',  $cyDesired, _
                                                    'uint', $fuLoad)
    Return $aResult[0]
    
EndFunc

Func GetModuleHandle($sModule = '')
    
    Local $aResult = DllCall($kernel32dll, 'hwnd', 'GetModuleHandle', 'ptr', StringLeft($sModule, 4095) & Chr(0))
    
    Return $aResult[0]
    
EndFunc

Func DeleteObject($hObject)
    
    Local $aResult = DllCall($gdi32dll, 'int', 'DeleteObject', 'hwnd', $hObject)
    Return $aResult[0]
    
EndFunc

Func MAKEINTRESOURCE($lID)
    
    Return "#" & String(Int($lID))
    
EndFunc

Func Terminate()
    
    For $i = 1 To 6
        
        DeleteObject($hBitmap[$i])
        
    Next
    
    DllClose($gdi32dll)
    DllClose($user32dll)
    DllClose($kernel32dll)
    
EndFunc

Greetz

Greenhorn

ProgressBarBitmap.zip

Share this post


Link to post
Share on other sites

Greenhorn your example looks very good. I have integrated this in one my scripts.

But I retrieve two problems

I cant set the progress back to the original state (0%) after I have used the Function one time.

And if you use also ModermenuRAW.au3 in your script you will get the error message that the DeleteObject() function is already defined.

I have use Greenhorns example to show what the problem is.

#NoTrayIcon
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=G:\AutoIT\sdoc_icon\Sdoc1.ico
#AutoIt3Wrapper_outfile=progr.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 1.bmp, bitmap, 1, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 2.bmp, bitmap, 2, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 3.bmp, bitmap, 3, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 4.bmp, bitmap, 4, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 5.bmp, bitmap, 5, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 6.bmp, bitmap, 6, 1031
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
;#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\Aut2Exe\upx.exe --best --compress-resources|1 "%out%"
#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <ProgressBar.au3>

Global Const $SS_CENTER = 1

; Wichtig ! s. Funktion.
Opt('OnExitFunc', 'Terminate')

; Array with Bitmaps from Disk !!!
Global $aPics[6] = ['1.bmp', '2.bmp', '3.bmp', '4.bmp', '5.bmp', '6.bmp']

; Array with Bitmaps from comp. exe !!!
;Global $aPics[6] = [1, 2, 3, 4, 5, 6]

; Testfenster erstellen.
$hWnd = GUICreate('ProgressBar mit Bitmaps - Demo', 500, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
GUISetBkColor(0xFFFFFF)
GUISetFont(10, 800, 0, 'SegoeUI')

GUICtrlCreateLabel('Progressbar Test', 0, 80, 500, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 12, 800, 0, 'SegoeUI')
$Run = GUICtrlCreateButton("RUN", 200, 220, 91, 25, 0)

$aProgressBar1 = ProgressBarCreate(100, 150, 300, $aPics, $hWnd)
ProgressBarSetState($aProgressBar1)

GUISetState(@SW_SHOW, $hWnd)

While True
    Switch GUIGetMsg()
        Case $Run
            TestProgress($aProgressBar1)
        Case -3
            Exit
    EndSwitch
WEnd

Func TestProgress($aProgress)
    For $i = 1 To 100
        ProgressBarSetData($aProgress, $i)
        Sleep(1)
    Next
    MsgBox(64, "Finished!", "Done!      ")
    Terminate()
EndFunc

Func Terminate()
; muss vor Programmende aufgerufen werden,
; um mit den Resourcen aufzuräumen.
    ProgressBarDelete($aProgressBar1)
;~  ProgressBarSetData($aProgressBar1, 0)
    ProgressBarSetState($aProgressBar1)
EndFunc

Greets

Christos

Share this post


Link to post
Share on other sites

Hi,

Just comment out one of the Funcs either in the ModernMenu.au3 or here.

I made it a little bit easier to use ...

I'll take a look at the script for resetting, but not today :)

Example.au3

#NoTrayIcon
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=progressEx2.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 1.bmp, bitmap, 1, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 2.bmp, bitmap, 2, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 3.bmp, bitmap, 3, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 4.bmp, bitmap, 4, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 5.bmp, bitmap, 5, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 6.bmp, bitmap, 6, 1031
#AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\Aut2Exe\upx.exe --best --compress-resources=1 "%out%"
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include 'ProgressBar.au3'

Global Const $SS_CENTER = 1

; Wichtig ! s. Funktion.
Opt('OnExitFunc', 'Terminate')

; Array mit Bitmaps von der Festplatte !!!
Global $aPics[6] = ['1.bmp', '2.bmp', '3.bmp', '4.bmp', '5.bmp', '6.bmp']

; Array mit Bitmaps aus den Resourcen !!!
;Global $aPics[6] = [1, 2, 3, 4, 5, 6]

; Testfenster erstellen.
$hWnd = GUICreate('ProgressBar mit Bitmaps - Demo', 500, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
GUISetBkColor(0xFFFFFF)
GUISetFont(10, 800, 0, 'SegoeUI')

GUICtrlCreateLabel('Progressbar Test', 0, 80, 500, 20, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 12, 800, 0, 'SegoeUI')

$aProgressBar1 = ProgressBarCreate(100, 150, 300, $aPics, $hWnd)
ProgressBarSetState($aProgressBar1)

GUISetState(@SW_SHOW, $hWnd)

$aProgressBar2 = ProgressBarCreate(100, 150, 1000, $aPics)
ProgressBarSetState($aProgressBar2)

Sleep(1500)
TestProgress($aProgressBar1)
TestProgress($aProgressBar2)

; muss vor Programmende aufgerufen werden,
; um mit den Resourcen aufzuräumen.
;ProgressBarDelete($aProgressBar1)
;ProgressBarDelete($aProgressBar2)

While True
    
    Switch GUIGetMsg()
        Case -3
            Exit
    EndSwitch
    
WEnd

Func TestProgress($aProgress)
    
    For $i = 1 To 100
        ProgressBarSetData($aProgress, $i)
        Sleep(1)
    Next
    
EndFunc

Func Terminate()
    
; muss vor Programmende aufgerufen werden,
; um mit den Resourcen aufzuräumen.
    ProgressBarDelete($aProgressBar1)
    ProgressBarDelete($aProgressBar2)
    
EndFunc

ProgressBar.au3

#include-once
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>



Func ProgressBarCreate($x, $y, $iWidth, $aBitmaps, $hWndParent = 0)
    
    Local $dwStyleCtrl, $dwExStyleCtrl, $aProgress[3][$iWidth + 1]
    $aProgress[1][0] = $iWidth
    $aProgress[0][3] = 1
    
    If Not IsArray($aBitmaps) Then
        Return SetError(1, 1, 0)
    EndIf
    
    Local $i, $eBmp, $fuLoad, $hInst, $hInstance  = GetModuleHandle()
    
    For $eBmp In $aBitmaps
        
        $i += 1
        If IsString($eBmp) Then
            $hInst  = Ptr(0)
            $fuLoad = 16
        ElseIf IsInt($eBmp) Then
            $hInst  = $hInstance
            $fuLoad = 0
        EndIf
        
        $aProgress[2][$i] = LoadImage($hInst, $eBmp, 0, 0, 0, $fuLoad)

    Next
    
    
    If Not $hWndParent Or $hWndParent = 0 Then
        $aProgress[0][0] = GUICreate('ProgressBar', $iWidth, 15, $x, $y, _
                                        BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), _
                                        BitOR(0x2000000, $WS_EX_LAYERED))
        $dwStyleCtrl   = BitOR(0x0100, $WS_CHILD)
        $dwExStyleCtrl = BitOr($WS_EX_LAYERED,$GUI_WS_EX_PARENTDRAG, $WS_EX_TOPMOST)
        $x = 0
        $y = 0
    Else
        $dwStyleCtrl   = $WS_CHILD
        $dwExStyleCtrl = $WS_EX_TOPMOST
    EndIf
    
    $aProgress[1][1] = GUICtrlCreatePic('', $x, $y, 2, 15, BitOR($dwStyleCtrl, $WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][1], 0x0172, 0, $aProgress[2][1])
    
    For $i = 2 To $iWidth - 3
        $aProgress[1][$i] = GUICtrlCreatePic('', $x + $i, $y, 1, 15, $dwStyleCtrl, $dwExStyleCtrl)
        GUICtrlSetState(-1, $GUI_ONTOP)
        GUICtrlSendMsg($aProgress[1][$i], 0x0172, 0, $aProgress[2][3])
    Next
    
    $aProgress[1][$iWidth] = GUICtrlCreatePic('', $x + $iWidth - 2, $y, 2, 15, BitOR($dwStyleCtrl, $WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][$iWidth], 0x0172, 0, $aProgress[2][2])
    
    $aProgress[0][1] = GUICtrlCreateLabel('0 %', $x + ($iWidth / 2) -15, $y, 40, 15, _
                                            BitOR($WS_VISIBLE, $WS_CLIPSIBLINGS, 1 , $dwStyleCtrl), $dwExStyleCtrl)
    GUICtrlSetFont(-1, 8.5, 800, 0, 'Segoe UI Fett')
    GUICtrlSetColor(-1,0x424242)
    
    If Not $hWndParent Then $aProgress[0][2] = GUICtrlSetTip(-1, "Drag me, please ...;) ")
    
    Return $aProgress
    
EndFunc

Func ProgressBarSetData(ByRef $aProgress, $iPercent)
    
    If $iPercent <= 0 Then Return 0
    $cxStart = $aProgress[0][3]
    $cxEnd = Int(($aProgress[1][0] / 100) * $iPercent)
    $aProgress[0][3] = $cxEnd + 1

    For $i = $cxStart To $cxEnd
        If $i = 1 Then
            GUICtrlSendMsg($aProgress[1][1], 0x0172, 0, $aProgress[2][5])
        ElseIf $iPercent = 100 And $i = Int($cxEnd) Then
            GUICtrlSendMsg($aProgress[1][$aProgress[1][0]], 0x0172, 0, $aProgress[2][6])
        Else
            GUICtrlSendMsg($aProgress[1][$i], 0x0172, 0, $aProgress[2][4])
        EndIf
        Sleep(0)
    Next
    
    ProgressBarSetText($aProgress, $iPercent & ' %')
    
EndFunc

Func ProgressBarSetState($aProgress, $State = @SW_SHOW)
    
    GUISetState($State, $aProgress[0][0])
    
    GUICtrlSetBkColor($aProgress[0][1], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetData($aProgress[0][1], '0 %')
    GUICtrlSetState($aProgress[0][1], $GUI_ONTOP)
    
EndFunc

Func ProgressBarSetText($aProgress, $sText)
    
    GUICtrlSetState($aProgress[0][1], $GUI_HIDE)
    GUICtrlSetData($aProgress[0][1], $sText)
    GUICtrlSetState($aProgress[0][1], $GUI_SHOW)

EndFunc

Func ProgressBarDelete($aProgress)
    
    If $aProgress[0][0] Then
        GUIDelete($aProgress[0][0])
    Else
        For $i = 1 To $aProgress[1][0]
            GUICtrlSendMsg($aProgress[1][$i], $WM_CLOSE, 0, 0)
        Next
    EndIf
    
    For $i = 1 To 6
        
        DeleteObject($aProgress[2][$i])
        
    Next
    
EndFunc



Func LoadImage($hInstance, $lpszName, $uType, $cxDesired = 0, $cyDesired = 0, $fuLoad = 0)
    
    If IsNumber($lpszName) Then $lpszName = MAKEINTRESOURCE($lpszName)
    Local $aResult = DllCall('user32.dll', 'hwnd', 'LoadImage', _
                                                    'ptr',  $hInstance, _
                                                    'str',  $lpszName, _
                                                    'uint', $uType, _
                                                    'int',  $cxDesired, _
                                                    'int',  $cyDesired, _
                                                    'uint', $fuLoad)
    Return $aResult[0]
    
EndFunc

Func GetModuleHandle($sModule = '')
    
    Local $aResult = DllCall('kernel32.dll', 'hwnd', 'GetModuleHandle', 'ptr', StringLeft($sModule, 4095) & Chr(0))
    
    Return $aResult[0]
    
EndFunc

Func DeleteObject($hObject)
    
    Local $aResult = DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hObject)
    Return $aResult[0]
    
EndFunc

Func MAKEINTRESOURCE($lID)
    
    Return "#" & String(Int($lID))
    
EndFunc

Greetz

Greenhorn

Edited by Greenhorn

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...