How to obtain the system accent colour on Windows?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

Hi there,

I am looking for a way to obtain the system accent colour on Windows 10/11 (i.e. the colour that can change based on the desktop wallpaper).

Is this possible?

Kind regards,

Francis
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: How to obtain the system accent colour on Windows?

Post by RASHAD »

Hi
Use registry
In my case it's $ffd77800

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Accent]
"AccentPalette"=hex:9a,eb,ff,00,61,cc,ff,00,00,93,fc,00,00,78,d7,00,00,5f,ba,\
  00,00,3f,95,00,00,1a,6a,00,88,17,98,00
"StartColorMenu"=dword:ffba5f00
"AccentColorMenu"=dword:ffd77800
OR

Code: Select all

[HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM]
"Composition"=dword:00000001
"ColorizationColor"=dword:c40078d7
"ColorizationColorBalance"=dword:00000059
"ColorizationAfterglow"=dword:c40078d7
"ColorizationAfterglowBalance"=dword:0000000a
"ColorizationBlurBalance"=dword:00000001
"EnableWindowColorization"=dword:00000000
"ColorizationGlassAttribute"=dword:00000001
"AccentColor"=dword:ffd77800
"ColorPrevalence"=dword:00000000
"EnableAeroPeek"=dword:00000001
"AlwaysHibernateThumbnails"=dword:00000000

Egypt my love
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

Thanks RASHAD! :D

Kind regards,

Francis
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

I've utilised Thomas "ts-soft" Schulz's registry code (viewtopic.php?t=56204) to create a quick example of obtaining Windows' system accent colour:

Code: Select all

XIncludeFile "Registry.pbi"
UseModule Registry

Procedure.l GetSystemAccentColor()
  ProcedureReturn Val(ReadValue(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\DWM", "AccentColor"))
EndProcedure

Debug "System accent colour: $" + Hex(GetSystemAccentColor(), #PB_Long)
Kind regards,

Francis
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: How to obtain the system accent colour on Windows?

Post by BarryG »

Code: Select all

Debug "System accent colour: $" + Hex(GetSystemAccentColor(), #PB_Long)
This shows $FFD6696B for me. Isn't that too long? Colors in hex have only 6 characters normally?
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

It's an RGBA value, so the initial $FF value is the alpha channel.

Kind regards,

Francis
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: How to obtain the system accent colour on Windows?

Post by BarryG »

Thanks for the explanation. So if we don't use the alpha channel, we can remove the leading $FF bit?
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

Yes, you could do something like this:

Code: Select all

RGB = GetSystemAccentColor() & $FFFFFF
Debug "System accent colour: $" + Hex(RGB, #PB_Long)
Kind regards,

Francis
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

I've expanded the example to include the other palette information.

Code: Select all

XIncludeFile "Registry.pbi"
UseModule Registry

Structure Palette
  RGB.l[8]
EndStructure

Procedure.l GetSystemAccentColor()
  ProcedureReturn Val(ReadValue(#HKEY_CURRENT_USER,
                                "Software\Microsoft\Windows\CurrentVersion\Explorer\Accent",
                                "AccentColorMenu"))
EndProcedure

Procedure.l GetSystemStartColorMenu()
  ProcedureReturn Val(ReadValue(#HKEY_CURRENT_USER,
                                "Software\Microsoft\Windows\CurrentVersion\Explorer\Accent",
                                "StartColorMenu"))
EndProcedure

Procedure.s GetSystemAccentPalette(*AccentPalette.Palette)
  Result$ = ReadValue(#HKEY_CURRENT_USER,
                      "Software\Microsoft\Windows\CurrentVersion\Explorer\Accent",
                      "AccentPalette")
  For i = 0 To 7
    Index = i * 4 + 1
    r = Val(StringField(Result$, Index,     ","))
    g = Val(StringField(Result$, Index + 1, ","))
    b = Val(StringField(Result$, Index + 2, ","))
    *AccentPalette\RGB[i] = RGB(r, g, b)
  Next
EndProcedure

Debug "System accent colour: $" + Hex(GetSystemAccentColor(), #PB_Long)
Debug "System start colour menu: $" + Hex(GetSystemStartColorMenu(), #PB_Long)

AccentPalette.Palette
GetSystemAccentPalette(@AccentPalette)
For i = 0 To 7
  Debug "System accent palette colour " + Str(i) + " = $" + Hex(AccentPalette\RGB[i])
Next
On my system, this produces the RGB/RGBA values for the following palette:



Kind regards,

Francis
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: How to obtain the system accent colour on Windows?

Post by RASHAD »

Thanks Francis :)
You saved me time for coding
Egypt my love
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: How to obtain the system accent colour on Windows?

Post by Dreamland Fantasy »

You're welcome RASHAD. :D

I'm not sure what each of the colours in the accent palette are for, but there they are. I haven't figured out how to work the AccentColorLight1-3 and AccentColorDark1-3 colors though. Seems this might be done on the fly and no one but Microsoft knows the algorithm.

Kind regards,

Francis
Post Reply