Click here to Skip to main content
15,662,926 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I must change color of title bar, from white to blue..I tried with:
<pre>

int CDlgEstimateTime::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	int aElements[2] = { COLOR_WINDOW, COLOR_ACTIVECAPTION };
	DWORD aOldColors[2];
	COLORREF new_c;


	//aNewColors[0] = RGB(0x80, 0x80, 0x80);  // light gray 
	new_c = RGB(255, 255, 255);  // dark purple 

	//SetSysColors(2, aElements, aNewColors);
	SetSysColors(2, aElements, &new_c);
	return 0;
}







it doesn't work, color of title bar doesn't change, but change color of CTrlList insdide my dialog, I don't know why..

What I have tried:

How Can I solve? I tried code that I've written

I tried:
<pre>
void CDlgEstimateTime::OnNcPaint() 
{
	/*CPaintDC dc(this); //<- calls `BeginPaint`
	dc.SelectStockObject(BLACK_PEN);
	dc.Rectangle(CRect(0, 0, 400, 400));
	*/
	COLORREF NewColor = RGB(255, 0, 0);
	int  flag = COLOR_ACTIVECAPTION;
	::SetSysColors(1, &flag, &NewColor);
	
} //<- EndPaint 


but sometimes it works and sometimes title bar is white, I don't know why
Posted
Updated 27-Sep-22 3:36am
v3

See GetSysColor function (winuser.h) - Win32 apps | Microsoft Learn[^]; most of these colour changes are no longer supported.

[edit]
Note that the third parameter should be an array of values corresponding to the aElements array: you have:
C++
new_c = RGB(255, 255, 255);  // dark purple
SetSysColors(2, aElements, &new_c);

Which is incorrect as new_c is not an array of colours. Also RGB(255, 255, 255) is white, not purple.
[/edit]
 
Share this answer
 
v2
Comments
Member 14594285 22-Sep-22 9:41am    
I know, in fact I tried whith black but it's the same thing...but is it right the function SetSysColors? How must I use it?
Richard MacCutchan 22-Sep-22 10:13am    
Yes, it is the right function. However, you need to follow the link I gave you and study the documentation for correct usage.
Member 14594285 22-Sep-22 11:34am    
I improved my question
Richard MacCutchan 22-Sep-22 11:41am    
And you are still using one of the values where the notes include:
Windows 10 or greater: This value is not supported.
Member 14594285 22-Sep-22 11:45am    
which value
I just tested the SetSysColors() example from Microsoft on Win10.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsyscolors
Absolutely nothing happens if you don't disable the visual styles with SetWindowTheme().
 
Share this answer
 
Comments
Member 14594285 23-Sep-22 2:52am    
I tried this code but now I have google with background gray and the title bar of my MFC application is white..I don't know

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