Page 1 of 1

How to get background color of a window?

Posted: Fri Jul 30, 2004 11:11 am
by Alberto
Hi,

when I use GetSystemColor I don't get the background color of a window

GetSysColor_(#COLOR_WINDOW)

give me the number 16777215 that is not the background color of the window.

16777215 it's the color with
RED = 255
GREEN = 255
BLUE = 255

There is another way to get the background color of a window? Or am I doing something wrong with GetSysColor_?

Regards
Alberto

Posted: Fri Jul 30, 2004 11:53 am
by srod

Code: Select all

A$=Space(40); Buffer which will receive data on the brush used to draw the background.
GetObject_(GetClassLong_(WindowID(),#GCL_HBRBACKGROUND),40,@A$)
bkcol=PeekL(@A$+4)  
Regards.

Posted: Fri Jul 30, 2004 12:04 pm
by PB
> GetSysColor_(#COLOR_WINDOW)
> give me the number 16777215 that is not the background color of the window

You're right -- it returns white for me too. I checked the Display Properties
and saw that #COLOR_WINDOW is referring to window backgrounds such as
Notepad's white background. If you change, in Display Properties, the value
of Window to red, then GetSysColor_(#COLOR_WINDOW) returns 255 (red),
and Notepad opens with a red background where you type the text. :)

After further checking the Display Properties settings, I found out that the
command you need is: GetSysColor_(#COLOR_3DFACE).

> bkcol=PeekL(@A$+4)

Returns 538976288 on my Win2K box, which is clearly wrong.

Posted: Fri Jul 30, 2004 12:07 pm
by srod
Works ok on XP. I use it to draw custom borders around gadgets; when the window is resized, I use the above routine to determine the window background colour and use it to effectively erase the border prior to redrawing it etc.

Posted: Fri Jul 30, 2004 12:36 pm
by PB
> Works ok on XP

I meant wrong as in the result on my 2K box; not wrong as in your code. :)

Posted: Fri Jul 30, 2004 2:34 pm
by Alberto
Thank you to PB and srod. :D

I will use GetSysColor_(#COLOR_3DFACE) that is good.

@srod:
I have Win XP professional and PeekL(@A$+4) give me the number 538976288 that is wrong.