You have a couple options here IMO - you can set up a background property on the progress object itself, like so:
Code: Select all
myGui := Gui()
ProgressControl := myGui.Add("Progress", "x0 h33 w300 Disabled")
;;Initialize the 'private' property that will shadow the dynamic prop below
ProgressControl._backgroundColor := ""
;;Define a setter that applies the options AND sets the 'private' property to shadow the input value,
;;the getter will then return that private property's value
ProgressControl.defineProp("BackgroundColor", {
get: (self)=>self._backgroundColor,
set: (self, newColor)=>(self.opt("+Background" . newColor), self._backgroundColor := newColor)
})
;;Set our initial background color, then report it back
ProgressControl.BackgroundColor := 0x202124
;;I'll use show here so you can see that the property works as described
myGui.Show()
msgbox(Format("{:#X}", ProgressControl.BackgroundColor), "Progress Bar Background Color")
;;Change our background color, then report it back
ProgressControl.BackgroundColor := 0x4f5156
msgbox(Format("{:#X}", ProgressControl.BackgroundColor), "Progress Bar Background Color (Again)")
(In this case, you'll always know what color the background is because you were the one that set the color to begin with.)
More robustly, you can use SendMessage to return the control's actual background color (
in BGR, not RGB) - this would work for any Win32 progress bar control, not just one created in AHK.
Links are included in the code comments to learn more:
Code: Select all
;;Reference the following links:
;; MSDocs for Control Messages:
;; https://docs.microsoft.com/en-us/windows/win32/controls/pbm-getbkcolor
;; Forum Post (from jeeswg, ca 2017) Re: the Values of Win32 messages:
;; https://www.autohotkey.com/boards/viewtopic.php?t=39218
myGui := Gui()
ProgressControl := myGui.Add("Progress", "x0 h33 w300 Background202124 Disabled")
;;Define the message constant
PBM_GETBKCOLOR := 0x40E
;;Use SendMessage to get the background color
;;Per the msdocs for this message, wparam and lparam need to be excluded/zero
bkgColor := SendMessage(PBM_GETBKCOLOR, , , ProgressControl.hwnd)
;;Format it in hex to compare it to the initial set value (0x202124) - notice the value returned is in BGR format
msgbox(Format("{:#X}", bkgColor), "Progress Bar Background Color")
;;Now change the background color and test again
ProgressControl.Opt("+Background4f5156")
;;The result here should be 0x56514f (BGR version of 0x4f5156)
bkgColor := SendMessage(PBM_GETBKCOLOR, , , ProgressControl.hwnd)
msgbox(Format("{:#X}", bkgColor), "Progress Bar Background Color (Again)")
You could also combine the two approaches, wrapping SendMessage into a getter and wrapping .Opt (or PBM_SETBKCOLOR) into the setter. In that case, you wouldn't need the ._BackgroundColor property.
I'll leave that as an exercise for you or someone else, but it would be the cleanest approach.