Jump to content
  • Advertisement

Archived

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

Abob

Get the background color of a window?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.
Header: Declared in wingdi.h.
Import Library: Included as a resource in msimg32.dll.

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



-G|aD-

Share this post


Link to post
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.



-G|aD-

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
If I understand correctly, since GetClassLong(window, GCL_HBRBACKGROUND) solution doesn''t work, GetSysColor() shouldn''t work either. Maybe I misunderstood what Abob is looking for.


-G|aD-

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!