Reputation: 11349
I am trying to use API GetBkColor and GetSysColor(COLOR_WINDOW) to get color of window but its giving me wrong value. When I get color of wndow by using some tool its diffeent from what I get from API.
Any suggestion of how to get right value of color?
In case if window is using gradient color then how can I find the color at particular pixel?
Upvotes: 2
Views: 3492
Reputation: 48038
GetBkColor
tells you the current background color for text, but the window may change it as it draws, so this isn't going to give you the value.
GetSysColor(COLOR_WINDOW)
is the recommended default color for a window given the current color scheme, but many windows choose a different color. You can try to get the WNDCLASS
for the window and check the hbrBackground
field, but not all windows rely on that mechanism for setting its background color.
To get the color at a particular pixel, you can use GetPixel
. This is fine for sampling a couple pixels, but don't try to read every pixel in a window by calling this a zillion times--it's too slow for that.
Upvotes: 0
Reputation: 765
GetBkColor returns value of a COLORREF value for the current background color on success. To obtain red, green and blue components of the color, use the GetRValue, GetGValue, and GetBValue macros, respectively. Is that what do you need? OR what kind of "right value" do you mean?
To obtain a pixel color, use GetPixel function:
COLORREF color;
HDC hdc_ = GetDC(NULL); //get dc of whole screen
color = GetPixel(hdc_, x, y);
Hope this will help you somehow.
Upvotes: 3