Sign in to follow this  
Followers 0
iamtheky

[SOLVED] GDI circle

9 posts in this topic

#1 ·  Posted (edited)

"code is largely comprised of something UEZ did I am sure" (as should be watermarked on all my GDI implementations)

I would like the circle to invert behavior every other time, but am having little success. That being after it unfills the first 5 seconds, the next 5 seconds would be filling the circle (rather than the current behavior of it snapping back to filled).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Color.au3>
#include <GDIP.au3>


_Circle()


Func _Circle()



    Local $h = 100
    Local $w = $h

    ; Initialize GDI+
    _GDIPlus_Startup()

    Local $hGUI = GUICreate("GDI+ Countdown Circle", $w, $h, @DesktopWidth - 100, @DesktopHeight - 100, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
;~ WinSetTrans($hGUI,"", 255)
    Local $bg = 0xFFFFFF
    GUISetBkColor($bg)
    _WinAPI_SetLayeredWindowAttributes($hGUI, $bg)

    GUISetState()

    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphics)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    ; Using antialiasing
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

    ; Create a Pen object
    Local $pen_size = Floor($h / 6)
    Global $hPen = _GDIPlus_PenCreate(0, $pen_size)

    ; Setup font parameters
    Local $fx
    Local $fsize = Floor($h / 10)
    Local $angle = 360
    Local $countdown_t = 5 ;seconds
    Local $countdown = $countdown_t
    Local $flash_color[3]
    Local $timer = TimerInit()
    Local $t_calc = Round(1000 * ($countdown_t + 1) / 360, 0)
    $flash_color[1] = 0x00
    $flash_color[2] = 0x00
    Local $z = 1
Local $lastcolor = Hex(random(0x000000, 0xFFFFFF), 6)
Local $randomColor = Hex(random(0x000000, 0xFFFFFF), 6)

    While 1

        _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
        _GDIPlus_PenSetColor($hPen, $lastcolor)
        _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, $hPen)
        If $countdown > 0 Then

            $flash_color[0] = Max(0xB0, Abs(0xFF * Sin($z / (0xC0 * $countdown))))
            _GDIPlus_PenSetColor($hPen, "0xFF" & $randomcolor)
            _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
        EndIf
;~
        If TimerDiff($timer) >= $t_calc Then
            $countdown -= $t_calc / 1000
            $timer = TimerInit()
            $angle = 360 * $countdown / $countdown_t
            $z += 2
        EndIf

        If $angle < 3 Then
            $angle = 360
            $timer = timerinit()
            $countdown_t = 5
            $countdown = $countdown_t
                        $lastcolor = $randomcolor
            $randomColor = Hex(random(0x000000, 0xFFFFFF), 6)
            
            Endif

    WEnd
EndFunc   ;==>_SHUTDOWN


Func Max($a, $b)
    If $a >= $b Then
        Return $a
    Else
        Return $b
    EndIf
EndFunc   ;==>Max
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You mean something like this?

;Fast hack by UEZ ;-)
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3"
#AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"

#include <Color.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Local $h = 150, $w = $h

; Initialize GDI+
_GDIPlus_Startup()

Local $hGUI = GUICreate("GDI+ Countdown Circle by UEZ", $w, $h, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
;~ WinSetTrans($hGUI,"", 255)
Local $bg = 0xFFFFFF
GUISetBkColor($bg)
_WinAPI_SetLayeredWindowAttributes($hGui, $bg)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()

Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

; Using antialiasing
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

; Create a Brush object
Local $tRectF = _GDIPlus_RectFCreate(0, 0, $w / 5, $h / 5)
Local $hBrush = _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, 0xFF008000, 0xFF00FF00, 45, True, 1)

; Create a Pen object
Local $pen_size = Floor($h / 6)
Local $hPen = _GDIPlus_PenCreate(0, $pen_size)
Local $hPen2 = _GDIPlus_PenCreate2($hBrush, $pen_size)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

; Setup font parameters
Local $fx, $sString
Local $font = "Arial"
Local $show_f = False
Local $show_bgc = False
Local $fsize = Floor($h / 12)
Local $angle = 0
Local $sf = "%.2f"

Local $p, $percent = False
Local $dir = 1
Local $i = 0
Local $max = 150

While Sleep(30)
    $p = $i / $max
    $angle = $p * 360
    If $angle < 0 Or $angle > 360 Then $dir *= -1
    _GDIPlus_GraphicsClear($hBackbuffer, 0xFFFFFFFF)
    _GDIPlus_PenSetColor($hPen, 0xFFE0FFE0)
    If $show_bgc Then _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, $hPen)
    _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen2)
    If $show_f Then
        If $percent Then
            $sString = $p  * 100
            $sf = "%.2f%"
            $fx = StringLen(StringFormat($sf, $sString)) * $fsize / 2.5
        Else
            $sString = $i
            $fx = StringLen(StringFormat($sf, $sString)) * $fsize / 2.5
        EndIf
        _GDIPlus_GraphicsDrawString($hBackbuffer, StringFormat($sf, $sString), $w / 2 - $fx, $h / 2 - $fsize * 0.75, $font, $fsize)
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
    $i += 1 * $dir
WEnd

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGui) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST

Func _Exit()

    ; Clean up
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)

    ; Uninitialize GDI+
    _GDIPlus_Shutdown()
    Exit
EndFunc

Func _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, $iARGBClr1, $iARGBClr2, $nAngle, $fIsAngleScalable = True, $iWrapMode = 0)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrushFromRectWithAngle", "ptr", $pRectF, "uint", $iARGBClr1, "uint", $iARGBClr2, "float", $nAngle, "int", $fIsAngleScalable, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[7]
EndFunc

Func _GDIPlus_PenCreate2($hBrush, $nWidth = 1, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePen2", "hwnd", $hBrush, "float", $nWidth, "int", $iUnit, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_PenCreate2

Here some additional stuff:

CPB.au3

;CPB - Circle Progress Bar v0.25 Build 2010-12-05 Alpha
#include-once
#include <GDIPlus.au3>
_GDIPlus_Startup()
Local $hGraphics_, $hBackbuffer_, $hBitmap_, $hBrush_, $tRectF_, $hPen2_, $hPen_, $pen_size_, $fsize_

Func CPB_Init($hWnd, $w, $h, $c1 = 0xFF008000, $c2 = 0xFF00FF00, $cb = 0xFFF0F0F0, $cangle = 45, $bs = 30, $ps = 6, $fs = 10)
    $hGraphics_ = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap_ = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphics_)
    $hBackbuffer_ = _GDIPlus_ImageGetGraphicsContext($hBitmap_)

    Local $ws = WinGetPos($hWnd)
    Local $gw = $ws[2], $gh = $ws[3]
    Local Const $GW_CHILD = 5
    Local Const $GW_HWNDNEXT = 2
    Local $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $gw, $gh))
    Local $hChild = _WinAPI_GetWindow($hWnd, $GW_CHILD)
    Local $aRect
    $aRect = ControlGetPos($hChild, "", 0)
    If Not @error Then
        Do
            $aRect = ControlGetPos($hChild, "", 0)
            If Not IsArray($aRect) Then ExitLoop
            _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
            $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
        Until Not $hChild
        _GDIPlus_GraphicsSetClipRegion($hGraphics_, $hRegion)
        _GDIPlus_RegionDispose($hRegion)
    EndIf
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer_, 2)

    $fsize_ = Floor($h / $fs)
    $tRectF_ = _GDIPlus_RectFCreate(0, 0, $bs, $bs)
    $hBrush_= _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF_, $c1, $c2, $cangle, True, 1)

    $pen_size_ = Floor($h / $ps)
    $hPen_ = _GDIPlus_PenCreate(0, $pen_size_)
    $hPen2_ = _GDIPlus_PenCreate2($hBrush_, $pen_size_)
EndFunc

Func CPB($current_, $max_, $x, $y, $w, $h,  $c3 = 0xFFE0FFE0, $cb = 0xFFF0F0F0, $show_font = True, $font_ = "Arial", $percent = False,  $fc = "%.2f")
    Local $angle_ = $current_ / $max_ * 360, $fx
    If $angle_ > 360 Then $angle_ = 360
    If $angle_ < 0 Then $angle_ = 0
    _GDIPlus_GraphicsClear($hBackbuffer_, $cb)
    _GDIPlus_PenSetColor($hPen_, $c3)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer_, $pen_size_ / 2, $pen_size_ / 2, $w - $pen_size_, $h - $pen_size_, $hPen_)
    _GDIPlus_GraphicsDrawArc($hBackbuffer_, $pen_size_ / 2, $pen_size_ / 2, $w - $pen_size_, $h - $pen_size_, -90, $angle_, $hPen2_)
    If $show_font Then
        If $percent Then
            $current_ = 100 * $current_ / $max_
            $fc &= "%"
        EndIf
        $fx = StringLen(StringFormat($fc, $current_)) * $fsize_ / 2.5
        _GDIPlus_GraphicsDrawString($hBackbuffer_, StringFormat($fc, $current_), $w / 2 - $fx, $h / 2 - $fsize_ * 0.75, $font_, $fsize_)
    EndIf
    _GDIPlus_GraphicsDrawImageRect($hGraphics_, $hBitmap_, $x, $y, $w, $h)
EndFunc

Func CPB_Close()
    _GDIPlus_BrushDispose($hBrush_)
    _GDIPlus_PenDispose($hPen_)
    _GDIPlus_PenDispose($hPen2_)
    _GDIPlus_BitmapDispose($hBitmap_)
    _GDIPlus_GraphicsDispose($hBackbuffer_)
    _GDIPlus_GraphicsDispose($hGraphics_)
    _GDIPlus_Shutdown()
EndFunc

Func _GDIPlus_LineBrushCreateFromRectWithAngle($tRectF, $iARGBClr1, $iARGBClr2, $nAngle, $fIsAngleScalable = True, $iWrapMode = 0)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrushFromRectWithAngle", "ptr", $pRectF, "uint", $iARGBClr1, "uint", $iARGBClr2, "float", $nAngle, "int", $fIsAngleScalable, "int", $iWrapMode, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[7]
EndFunc

Func _GDIPlus_PenCreate2($hBrush, $nWidth = 1, $iUnit = 2)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePen2", "hwnd", $hBrush, "float", $nWidth, "int", $iUnit, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[4]
EndFunc   ;==>_GDIPlus_PenCreate2

Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc

Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
EndFunc

Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult
    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc

Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
EndFunc

CPB Example.au3

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

#include "CPB.au3"

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Local $w = 350, $h = 211
Local $hGUI = GUICreate("GDI+ Countdown Circle", $w, $h)
Local $Label1 = GUICtrlCreateLabel("GDI+ Countdown Circle", 16, 8, 319, 40)
GUICtrlSetFont(-1, 24, 400, 0, "Times New Roman")
Local $Label2 = GUICtrlCreateLabel("Max. Value:", 8, 67, 71, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Local $Input = GUICtrlCreateInput("150", 80, 64, 80, 21)
Local $Button_Start = GUICtrlCreateButton("Start Progressbar", 16, 120, 147, 81)
Local $Button_Exit = GUICtrlCreateButton("Exit", 253, 145)
Local $Group = GUICtrlCreateGroup("UEZ 2010", 2, 45, 180, 162)
Local $bgc = "C0D0FF"
GUISetBkColor("0x" & $bgc, $hGUI)
WinSetTrans($hGUI,"", 255)
GUISetState()

Local $CBP_dim = 145
CPB_Init($hGUI, $CBP_dim, $CBP_dim)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlSetOnEvent($Button_Exit, "_Exit")
GUICtrlSetOnEvent($Button_Start, "Start")

Local $i = 0,  $end = GUICtrlRead($Input)
CPB($i, $end, 192, 56, $CBP_dim, $CBP_dim, 0xFFE0FFE0, "0xFF" & $bgc)

While Sleep(1000)
WEnd

Func Start()
    $end = GUICtrlRead($Input)
    GUICtrlSetState($Button_Start, $GUI_DISABLE)
    GUICtrlSetState($Button_Exit, $GUI_DISABLE)
    GUICtrlSetState($Input, $GUI_DISABLE)
    For $i = 0 To $end
        CPB($i, $end, 192, 56, $CBP_dim, $CBP_dim, 0xFFE0FFE0, "0xFF" & $bgc, True, "Arial", False)
        Sleep(20)
    Next
    GUICtrlSetState($Button_Start, $GUI_ENABLE)
    GUICtrlSetState($Button_Exit, $GUI_ENABLE)
    GUICtrlSetState($Input, $GUI_ENABLE)
    Return 1
EndFunc

Func _Exit()
    CPB_Close()
    GUIDelete($hGUI)
    Exit
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Maybe something like this.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

_Circle()


Func _Circle()
    Local $h = 100
    Local $w = $h

    ; Initialize GDI+
    _GDIPlus_Startup()

    Local $hGUI = GUICreate("GDI+ Countdown Circle", $w, $h, @DesktopWidth - 100, @DesktopHeight - 100, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    ;WinSetTrans($hGUI,"", 255)
    Local $bg = 0xFFFFFF
    GUISetBkColor(0xABCDEF)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF)

    GUISetState()

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphics)
    Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    ; Using antialiasing
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

    ; Create a Pen object
    Local $pen_size = Floor($h / 6)
    Local $hPen = _GDIPlus_PenCreate(0, $pen_size)
    Local $hPen1 = _GDIPlus_PenCreate(0, $pen_size)

    ; Setup font parameters
    Local $fsize = Floor($h / 10)
    Local $angle = 360
    Local $countdown_t = 5 ;seconds
    Local $countdown = $countdown_t
    Local $timer = TimerInit()
    Local $t_calc = Round(1000 * ($countdown_t + 1) / 360, 0)
    Local $z = 1
    Local $lastcolor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
    Local $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))

    While 1
        If GUIGetMsg() = -3 Then ExitLoop
        _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000)
        _GDIPlus_PenSetColor($hPen1, $randomColor)
        _GDIPlus_PenSetColor($hPen, $lastcolor)
        _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, $hPen)

        If $countdown > 0 Then
            _GDIPlus_PenSetColor($hPen, "0xFF" & $randomColor)
            _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, -360 + $angle, $hPen1)
            _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
        EndIf
;~
        If TimerDiff($timer) >= $t_calc Then
            $countdown -= $t_calc / 1000
            $timer = TimerInit()
            $angle = 360 * $countdown / $countdown_t
            $z += 2
        EndIf

        If $angle < 3 Then
            $angle = 360
            $timer = TimerInit()
            $countdown_t = 5
            $countdown = $countdown_t
            $lastcolor = $randomColor
            $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
        EndIf
    WEnd
    _GDIPlus_GraphicsDispose($hGraphics)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
EndFunc   ;==>_Circle

Func Max($a, $b)
    If $a >= $b Then
        Return $a
    Else
        Return $b
    EndIf
EndFunc   ;==>Max

Share this post


Link to post
Share on other sites

Uez, I am now aware there are two meanings to my question. I may someday have use for that effect though, and some nice browser left some HTML in your code.

Local $show_f = [size=2] False[/size]

Malkey, that was the precise intent of my efforts, thank you sir.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Since the Forum upgrade at beginning of November I got several problems to modify my posts but who cares?

Should be fixed now hopefully.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks for your assistance, this is the resulting progress circle. Used to show that something is still occuring when all other activity on the screen may be at a standstill.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

_Circle()

Func _Circle()
    Local $h = 100
    Local $w = $h

    ; Initialize GDI+
    _GDIPlus_Startup()

    Local $hGUI = GUICreate("GDI+ Circle", $w, $h, @DesktopWidth - 100, @DesktopHeight - 100, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    ;WinSetTrans($hGUI,"", 255)
    Local $bg = 0xFFFFFF
    GUISetBkColor(0xABCDEF)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF)

    GUISetState()

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphics)
    Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    ; Using antialiasing
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

    ; Create a Pen object
    Local $pen_size = Floor($h / 6)
    Local $hPen = _GDIPlus_PenCreate(0, $pen_size)
    Local $hPen1 = _GDIPlus_PenCreate(0, $pen_size)

    ; Setup font parameters
    Local $fsize = Floor($h / 10)
    Local $angle = 360
    Local $countdown_t = 5 ;seconds
    Local $countdown = $countdown_t
    Local $timer = TimerInit()
    Local $t_calc = Round(1000 * ($countdown_t + 1) / 360, 0)
    Local $z = 1
    Local $lastcolor = "0x00ABCDEF"
    Local $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))

    While 1
        If GUIGetMsg() = -3 Then ExitLoop
        _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000)
        _GDIPlus_PenSetColor($hPen1, $randomColor)
        _GDIPlus_PenSetColor($hPen, $lastcolor)
        _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, $hPen)

        If $countdown > 0 Then
            _GDIPlus_PenSetColor($hPen, "0xFF" & $randomColor)
            _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, -360 + $angle, $hPen1)
            _GDIPlus_GraphicsDrawArc($hBackbuffer, $pen_size / 2, $pen_size / 2, $w - $pen_size, $h - $pen_size, -90, $angle, $hPen)
            _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $w, $h)
        EndIf
;~
        If TimerDiff($timer) >= $t_calc Then
            $countdown -= $t_calc / 1000
            $timer = TimerInit()
            $angle = 360 * $countdown / $countdown_t
            $z += 2
        EndIf

            IF $angle > 89 and $angle < 91 Then
            $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
            Endif

            IF $angle > 179 and $angle < 181 Then
            $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
            Endif

            IF $angle > 269 and $angle < 271 Then
            $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
            Endif


        If $angle < .1 Then
            $angle = 360
            $timer = TimerInit()
            $countdown_t = 5
            $countdown = $countdown_t
            $lastcolor = $randomColor
            $randomColor = Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))
        EndIf
    WEnd
    _GDIPlus_GraphicsDispose($hGraphics)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_Shutdown()
EndFunc   ;==>_Circle

Func Max($a, $b)
    If $a >= $b Then
        Return $a
    Else
        Return $b
    EndIf
EndFunc   ;==>Max

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The OPs code didnt have that, I blame malkey :x

But I also blame him for the success in making it change all nicely,

can I inquire as to the benefits or lack thereof offered by the bonus execute function

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Malkey & iamtheky

Why are you using Execute, that looks unnecessary. The script works without it.

Correct, the "Execute" in "Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))" is not needed for the script to work correctly . I blindly copied Prog@ndy's example as he used in his _WinAPI_SetLayeredWindowAttributes() function in the WinAPI.au3 include file.

Thinking about why "Execute" was used may be about supplying a parameter with the correct variable type. A good procedural habit (discipline) learnt from other languages. AutoIt is a lot more forgiving.

"Execute("0xFF" & Hex(Random(0x000000, 0xFFFFFF), 6))" becomes the $iARGB parameter in the _GDIPlus_PenSetColor() function. Within this function, $iARGB is entered into a DllCall() as a 'dword', a 32bit unsigned integer. For example, 0xFF0000FF, or, convert a string to an int32 using Execute() or Dec(Hex()).

There may be others reasons why Prog@ndy used Execute() with the $iARGB parameter that I am not aware of.

All the following variable types string, int32, and int64, work as a suitable $iARGB parameter for the _GDIPlus_PenSetColor() function in the above script.

$string1 = "0xFF0000FF"
ConsoleWrite('$string1 is a variable type ' & @TAB & VarGetType($string1) & @TAB & _
        ' which contains "0xFF0000FF"           = ' & @TAB & $string1 & @CRLF)

$string2 = Hex("0xFF0000FF")
ConsoleWrite('$string2 is a variable type ' & @TAB & VarGetType($string2) & @TAB & _
        ' which contains Hex("0xFF0000FF")      = ' & @TAB & $string2 & @CRLF)

$int32 = 0xFF0000FF
ConsoleWrite('$int32   is a variable type ' & @TAB & VarGetType($int32) & @TAB & _
        ' which contains 0xFF0000FF             = ' & @TAB & $int32 & @CRLF)
$int32A = Dec(Hex("0xFF0000FF"))
ConsoleWrite('$int32A  is a variable type ' & @TAB & VarGetType($int32A) & @TAB & _
        ' which contains Dec(Hex("0xFF0000FF")) = ' & @TAB & $int32A & @CRLF)

$int32B = Execute("0xFF0000FF")
ConsoleWrite('$int32B  is a variable type' & @TAB & VarGetType($int32B) & @TAB & _
        ' which contains Execute("0xFF0000FF")  = ' & @TAB & $int32B & @CRLF)

$int64 = Number("0xFF0000FF")
ConsoleWrite('$int64   is a variable type' & @TAB & VarGetType($int64) & @TAB & _
        ' which contains Number("0xFF0000FF")   = ' & @TAB & $int64 & @CRLF)

Results are:-

$string1 is a variable type     String  which contains "0xFF0000FF"         =   0xFF0000FF
$string2 is a variable type     String  which contains Hex("0xFF0000FF")      =     FF0000FF
$int32   is a variable type     Int32   which contains 0xFF0000FF           =   -16776961
$int32A  is a variable type     Int32   which contains Dec(Hex("0xFF0000FF")) =     -16776961
$int32B  is a variable type     Int32   which contains Execute("0xFF0000FF")  =     -16776961
$int64   is a variable type     Int64   which contains Number("0xFF0000FF")   =     4278190335
Edited by Malkey

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