How to get the system color of a display element

2 10 2012

Sometime we may need to get the system defined RGB value of a display elements (user controls) like dialog, scrollbar, button, listbox etc. How do we get it?

Windows provides an API GetSysColor to retrieve the current color of the specified display element.

DWORD GetSysColor(int nIndex);

int nIndex – The display element whose color is to be retrieved. It can be CTLCOLOR_DLG, CTLCOLOR_SCROLLBAR, CTLCOLOR_BTN, CTLCOLOR_LISTBOX etc.

The function returns the red, green, blue (RGB) color value of the given element.

void GetSystemDefinedColor()
{
	//Dialog System defined color
	DWORD dwControlColor = ::GetSysColor(CTLCOLOR_DLG);
	int r = GetRValue(dwControlColor);
	int g = GetGValue(dwControlColor);
	int b = GetBValue(dwControlColor);

	//Listbox System defined color
	dwControlColor = ::GetSysColor(CTLCOLOR_LISTBOX);
	r = GetRValue(dwControlColor);
	g = GetGValue(dwControlColor);
	b = GetBValue(dwControlColor);
}

SetSysColors API can be used to set the colors for specified display elements.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: