Click here to Skip to main content
15,746,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I Change the window color in c++? (Windows 10)

I want the caption color to be yellow. I looked everywhere by searching it on google and I still can't find the right solution to it. Is there a way to change the window caption color?

What I have tried:

int windowColor = 0;
HWND window = GetActiveWindow();
LONG exStyle = GetWindowLong(window, GWL_EXSTYLE);
SetWindowLong(window, GWL_EXSTYLE, exStyle);
DwmSetWindowAttribute(window, 21, &windowColor, sizeof(windowColor));
Updated 6-Apr-23 23:16pm
Gerry Schmitz 6-Apr-23 10:01am    
Maybe you need to switch to a more "modern" language if you want to do UI development.

It's not a good idea: not only does it do directly against what the user has specified he wants Windows to look like, it's a lot of trouble.
Basically, you can't do it - not without changing the whole non-client area and that gets ... hairy.

Have a look here:[^]
Share this answer
Gerry Schmitz 6-Apr-23 10:10am    
Check the VS title bar: it's blue. My particular app benefits from a "black" title bar, which idea I took from the MS "master" samples.
SomeGuyWhoLovesCoding 6-Apr-23 10:20am    
I want the border color to be yellow.
And I want it be be like this in Windows 10:
Take a look at WM_NCPAINT message (Winuser.h) - Win32 apps | Microsoft Learn[^]. Although this requires considerable work to make it happen.
Share this answer
You really should use values from the enumeration instead of literal values. Here are the values : DwmSetWindowAttribute enumeration[^]. If I am reading the list correctly, there is no enumerated value 21. I would guess you want to use attribute DWMWA_CAPTION_COLOR. It appears that Windows 11 is required to do this so you may be out of luck with that route for W10.

The only alternative I can think of was mentioned previously and that is to override WM_NCPAINT. I don't recommend that because it opens a rather large can of worms but I know of no other options. For more info on that you should go to your search engine of choice and look for "wm_ncpaint example". You will find a lot of stuff on that topic.
Share this answer
I have copied the existing code into a VS program framework for test.

The call of DwmSetWindowAttribute() with DWMWA_CAPTION_COLOR (and also the undocumented value 21) fails, which can be seen also with return value. According to the documentation, the DWMWA_CAPTION_COLOR flag is supported with DwmSetWindowAttribute() only from Windows 11 Build 22000.

The error code for Windows10 is E_INVALIDARG (One or more arguments are invalid.).

According to the documentation it is required that "client area rendering" is disabled, which it obviously is not by default.

Controlling non - client region rendering


// disable non - client area rendering
hr = DisableNCRendering(hWnd);

// check state of NCRendering
BOOL isNCRenderingEnabled{ FALSE };
hr = DwmGetWindowAttribute(hWnd, DWMWA_NCRENDERING_ENABLED, &isNCRenderingEnabled, sizeof(isNCRenderingEnabled));

// Specify the color of the caption.
COLORREF  mycolor = 0;
hr = DwmSetWindowAttribute(hWnd, DWMWA_CAPTION_COLOR, &mycolor, sizeof(mycolor));

There's an undocumented window attribute allowing dark mode title bars (DWMWA_USE_IMMERSIVE_DARK_MODE). Apparently this flag does not work under Win10 either.

We have also discussed this question many times and there are also CodeProject articles that deal with it. Unfortunately, Microsoft has changed a lot in the meantime, so that these articles either don't work anymore or can't be compiled.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900