Sign in to follow this  
Followers 0
jiglei

[Help] Custom Progress Bar UDF

5 posts in this topic

Hey guys, I managed to do a UDF that allows you to design progress bars, with the colors you want to, which is useful for who doesn't use Windows Classic theme, and still want to color those progresses. I found some skin GUI's UDF's that would work, but, I figured doing my own would be simple.

I was also planning on doing more functions for this UDF, like re-setting the values and even colors, but, I got stuck at one part...

To this UDF, I had an idea to also add a label, directly on the middle of the bar, since the a label there would print the background color of itself over the progress bar, I thought if I did a transparent gui right over the bar, and make the label background the same color the gui, that should do it transparent too. But, for some reason, the child window does not appear...

I read on the Helpfile about the details on $WS_EX_LAYERED:

" $WS_EX_LAYERED Creates a layered window. Note that this cannot be used for child windows. "

But, right down on the example script, there's an example on how to do a child window transparent lol.

example2()
Func Example2()
    Local $gui, $background, $pic, $basti_stay, $msg
    Local $sFile = "..\GUI\logo4.gif"
    
    $gui = GUICreate("Background", 400, 100)
    ; background picture
    $background = GUICtrlCreatePic("..\GUI\msoobe.jpg", 0, 0, 400, 100)
        
    GUISetState(@SW_SHOW)

    ; transparent MDI child window
    $pic = GUICreate("", 169, 68, 20, 20, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
    ; transparent pic
    $basti_stay = GUICtrlCreatePic($sFile, 0, 0, 169, 68)
    GUISetState(@SW_SHOW)

    Do
        $msg = GUIGetMsg()

    Until $msg = $GUI_EVENT_CLOSE

I've also tried other guis to become transparent with images and text on a child window.

But, for some damn reason, on my UDF, it doesn't work!

Can someone give me a hand? I'm driving nuts over this issue...

Here's my UDF as it is now:

; #FUNCTION# ==================================================================================================================================================================================================================
; Name...........: _SMTF_CreateProgress
; Description ...: Encrypts data
; Syntax.........: _SMTF_CreateProgress ($HWDGUI, $iLeft, $iTop, $iWidth, $iHeight,$iBarColor,$iBKColor [, [$ilabel=0, $iState=0, [$iBorder=1, [$iBorderColor=0x000000)
; Parameters ....: $HWDGUI       -> Handle of the GUI where to create the progress. If "" then the last one will be applied
;                  $iLeft        -> The left coordinate position of the progress
;                  $iTop         -> The top coordinate position of the progress
;                  $iWidth       -> The width of the progress
;                  $iHeight      -> The height of the progress
;                  $iBarColor    -> The initial Bar color
;                  $iBKColor     -> The initial Background color of the progress
;                  $iState       -> The initial percentage (%) of the progress. Default is 0
;                  $ilabel       -> Optional, a label centered within the progress. If this is 1, then the % of the bar will be shown, else, the text. If zero, no label will be created
;                  $ilabelColor  -> The color of the text on the optional label, the default is black text
;                  $iBorder      -> The initial border width. Default is 1 pixel. Bigger size may not work
;                  $iBorderColor -> The initial border color. Default is black (0x000000)
; Requirement(s).: v3.3.6.0 or higher
; Return values .: Success - Returns a one dimension array corresponding to the handles of the labels designing the progress. Following the protocol:
;                       Array[0] = The handle for the label designing the left border
;                       Array[1] = The handle for the label designing the top border
;                       Array[2] = The handle for the label designing the right border
;                       Array[3] = The handle for the label designing the bottom border
;                       Array[4] = The handle for the label designing the background of the bar
;                       Array[5] = The handle for the label designing the bar itself
;                       Array[6] = The handle for the transparent GUI where the label is
;                       Array[7] = The handle for the label that is over the bar. If it isn't created then this value will be zero.
;
;                  Failure - Returns the following errors under the ocasions:
;                       -1 - The given GUI Handle points to a window that does not exist.
;                        0 - One of the parameters is invalid.
; Remarks .......; None
; Author ........: Mike The Fox
; Example........; No
;==========================================================================================================================================================================================================================================

Func _SMTF_CreateProgress(ByRef $HWDGUI, $iLeft, $iTop, $iWidth, $iHeight, $iBarColor, $iBKColor, $iState = 0, $ilabel = 0, $ilabelColor = 0x000000, $iBorder = 1, $iBorderColor = 0x000000)
    Local $ProgressLabels[8], $n

    If $HWDGUI <> "" Then ;If Handle is different from "" switch the gui
        If WinExists($HWDGUI) = 0 Then Return -1 ; Return -1 in case the window doesn't exist
        GUISwitch($HWDGUI) ;Switching GUI
    EndIf
    If $iLeft = "" Or $iTop = "" Or $iWidth = "" Or $iHeight = "" Or $iBarColor = "" Or $iBKColor = "" Then Return 0
    $ProgressLabels[0] = GUICtrlCreateLabel("", $iLeft, $iTop, $iBorder, $iHeight);Create left border
    $ProgressLabels[1] = GUICtrlCreateLabel("", $iLeft, $iTop, $iWidth, $iBorder);Create top border
    $ProgressLabels[2] = GUICtrlCreateLabel("", $iLeft + $iWidth, $iTop, $iBorder, $iHeight + $iBorder);Create right border
    $ProgressLabels[3] = GUICtrlCreateLabel("", $iLeft, $iTop + $iHeight, $iWidth, $iBorder);Create bottom border
    For $n = 0 To 3
        GUICtrlSetBkColor($ProgressLabels[$n], $iBorderColor);Coloring the Borders
    Next
    $ProgressLabels[4] = GUICtrlCreateLabel("", $iLeft + $iBorder, $iTop + $iBorder, $iWidth - $iBorder, $iHeight - $iBorder);Create progress background
    GUICtrlSetBkColor($ProgressLabels[4], $iBKColor);Coloring the background
    $ProgressLabels[5] = GUICtrlCreateLabel("", $iLeft + $iBorder, $iTop + $iBorder, ($iWidth - $iBorder) * ($iState / 100), $iHeight - $iBorder);Create the bar
    GUICtrlSetBkColor($ProgressLabels[5], $iBarColor);Coloring the bar
    If $ilabel <> 0 Or $ilabel <> "" Then ;If the user choses to create a label...
        $ProgressLabels[6] = GUICreate("", $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $HWDGUI);Creates a transparent GUI to hold the label
        GUISetBkColor($ilabelColor + 500, $ProgressLabels[6])
        $ProgressLabels[7] = GUICtrlCreateLabel($ilabel, 0, 0, $iWidth, $iHeight, $SS_Center);Create the label centered within the progress
        GUICtrlSetBkColor($ProgressLabels[7], $ilabelColor + 500)
        GUICtrlSetColor($ProgressLabels[6], $ilabelColor);Colors the text on the label according to the specification
        GUISetState(@SW_SHOW, $ProgressLabels[6])
    Else ;If not...
        $ProgressLabels[6] = 0 ;This handle shall be zero
        $ProgressLabels[7] = 0 ;And this too
    EndIf
    Return $ProgressLabels ;Returns the array
EndFunc   ;==>_SMTF_CreateProgress

Thanks in advance.

Share this post


Link to post
Share on other sites



Are you aware that you can disable theming on the Progress-control ONLY?

Example=

$hGUI = GUICreate("Test", 200, 40)

$hProgress = GUICtrlCreateProgress(10, 10, 180, 20)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hProgress), "wstr", 0, "wstr", 0)

GUISetState()

AdlibRegister("_Progress")

Do
Until GUIGetMsg() = -3

Func _Progress()
    GUICtrlSetData(-1, Random(0, 100, 1))
    GUICtrlSetColor(-1, Random(0, 0xFFFFFF, 1))
EndFunc

Share this post


Link to post
Share on other sites

No, I had no ideia :(

Thanks a lot, that does help.

But I'd still like to finish my UDF anyways :S. I was going to add gradient colors support too :graduated:

Share this post


Link to post
Share on other sites

Bump, I need help specialy on this:

If $ilabel <> 0 Or $ilabel <> "" Then ;If the user choses to create a label...
;I need to know why is this gui not becoming visible
        $ProgressLabels[6] = GUICreate("", $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $HWDGUI);Creates a transparent GUI to hold the label
        GUISetBkColor($ilabelColor + 500, $ProgressLabels[6])
        $ProgressLabels[7] = GUICtrlCreateLabel($ilabel, 0, 0, $iWidth, $iHeight, $SS_Center);Create the label centered within the progress
        GUICtrlSetBkColor($ProgressLabels[7], $ilabelColor + 500)
        GUICtrlSetColor($ProgressLabels[6], $ilabelColor);Colors the text on the label according to the specification
        GUISetState(@SW_SHOW, $ProgressLabels[6])

Thanks in advance, and special thanks to AdmiralAlkex for the example above.

Share this post


Link to post
Share on other sites

Found a workaround on my own. Thanks, you may close the topic.

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