Skip to content

SetColor() failing on Windows 10 when no GUI.BackColor is explicitly specified #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LeoTN opened this issue Apr 25, 2025 · 0 comments

Comments

@LeoTN
Copy link

LeoTN commented Apr 25, 2025

Hey, thank you for creating this library! It is a really nice addition to the "boring" windows buttons.

Issue 1

While implementing it in my own project, I discovered an issue on my Windows 10 VM which probably affects most Windows 10 users.

I am using the code from the original file to explain the issue(s) properly.

myGui := Gui("Resize")
; The default value of this property is an empty string.
myGui.BackColor := 0x202020

btn := myGui.AddButton("xm w300", "This button is colored successfully when myGUI.BackColor is explicitly specified")
btn.SetColor("0xaa2031", "FFFFCC", , "fff5cc", 9)

myGui.Show("w280 AutoSize")

When myGUI.BackColor is explicitly specified to be "0x202020" in this case, the SetColor() function works properly on both Windows 10 and 11. However, if you do not specify myGUI.BackColor, it's value would be an empty string by default.

This isn't a problem on Windows 11, as the condition below seems to affect the outcome of the operation, which avoids the issue, but causes a problem on Windows 10.
this._btnBkColor := (colorBehindBtn ?? !IS_WIN11) && _BtnColor.RgbToBgr("0x" (this.Gui.BackColor))

Error Message 1

On Windows 10, I received the following error message:

Error: Parameter #1 of Number.Call requires a Number, but received a String.

Specifically: 0x

550: }
553: {
▶ 553: Return (Type(color) = "string") ? this.RgbToBgr(Number(SubStr(Color, 1, 2) = "0x" ? color : "0x" color )) : (Color >> 16 & 0xFF) | (Color & 0xFF00) | ((Color & 0xFF) << 16)
553: }
557: myGui := Gui("Resize")

Call stack:
C:\Users\User\Downloads\ColorButton.ahk-1.3.1\ColorButton.ahk (553) : [Number.Call] Return (Type(color) = "string") ? this.RgbToBgr(Number(SubStr(Color, 1, 2) = "0x" ? color : "0x" color )) : (Color >> 16 & 0xFF) | (Color & 0xFF00) | ((Color & 0xFF) << 16)
C:\Users\User\Downloads\ColorButton.ahk-1.3.1\ColorButton.ahk (553) : [_BtnColor.RgbToBgr] Return (Type(color) = "string") ? this.RgbToBgr(Number(SubStr(Color, 1, 2) = "0x" ? color : "0x" color )) : (Color >> 16 & 0xFF) | (Color & 0xFF00) | ((Color & 0xFF) << 16)
C:\Users\User\Downloads\ColorButton.ahk-1.3.1\ColorButton.ahk (359) : [_BtnColor.Prototype.SetColor] this._btnBkColor := (colorBehindBtn ?? !IS_WIN11) && _BtnColor.RgbToBgr("0x" (this.Gui.BackColor))
C:\Users\User\Downloads\ColorButton.ahk-1.3.1\ColorButton.ahk (562) : [] btn.SetColor("0xaa2031", "FFFFCC", , "fff5cc", 9)
→ Auto-execute

Issue 2

This issue can be reproduced by running the same code from above on a Windows 10 machine (or changing static IS_WIN11 := false). It probably has to do with the first issue and occurs when I try to close the GUI.

Error Message 2

Error: This value of type "Gui.Button" has no property named "__hbrush".

369: {
▶ 369: Return DeleteObject(this.__hbrush)
369: }
369: this.Gui.OnEvent("Close", (*) => DeleteObject(this.__hbrush))

Call stack:
C:\Users\User\Downloads\ColorButton.ahk-1.3.1\ColorButton.ahk (369) : [] Return DeleteObject(this.__hbrush)
→ Gui

Summary

It is possible to avoid the first issue by explicitly specifying a value for myGui.BackColor, but most of the time people either forget to do that or simply want to use the default color. However, I couldn't find a way to address the second issue, which happens when you try to close the GUI containing any colored button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant