• Popular Now

• 15
• 15
• 11
• 9
• 10

Archived

This topic is now archived and is closed to further replies.

Get the background color of a window?

This topic is 5671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Is there a way to get the background color of a window? To get what the hbrBackground member of the WINCLASS is set to? Thanks for any help.

Share on other sites
GetClassLong(window, GCL_HBRBACKGROUND)

Share on other sites
GetClassLong(window, GCL_HBRBACKGROUND)
Worked.
But I guess it wasn’t what I need.

I am coding a custom WIN32 control.
And what I need is a way to get the proper color to fill in the background of the control.
The color can’t be hard coded, because Windows can run in many deferent color schemes.
And use deferent colors for the background of a dialog.

Thanks for any help

Share on other sites
HDC hDC = GetDC(hWindow);
COLORREF brushColor = GetDCBrushColor(hDC);
ReleaseDC(hWindow, hDC);

// use brushColor to paint your control

GetDCBrushColot() QuickInfo:

Windows NT: Requires version 5.0 or later.
Windows: Requires Windows 98.
Windows CE: Unsupported.
Import Library: Included as a resource in msimg32.dll.

That means Win98+ & WinNT 5+. Obviously you can''t use this function on Win95.

Share on other sites
You can also try this:

HDC hDC = GetDC(hWindow);
COLORREF brushColor = GetPixel(hDC, 0, 0);
ReleaseDC(hWindow, hDC);

This will work for all versions of windows. Just make sure it does what you want.

Share on other sites
Or use GetSysColor, which will retrieve a color from the system color scheme:

COLORREF clrButtonFace = GetSysColor(COLOR_BTNFACE);// use clrButtonFace to draw stuff