get the windows backcolor

Hi there

I’m trying to get the window backcolor and it seems i can’t.

i am NOT setting a backcolor on the window, i want to know what the current colour of the window is (the one set in windows control panel)

does anyone know how i get this ?

http://documentation.xojo.com/index.php/Window.Backcolor

If me.HasBackColor Then Dim c As Color = me.BackColor End If

thanks Oliver, but…

what i really want is

if NOT me.Hasbackcolor then
dim c as color = me.backcolor // i know this doesn’t work, but there is still a colour there. what is it?
end if

I just tried to get the default window BackColor by doing a DrawInto in a picture and then looking at that with RGBSurface Pixel. No luck, All I get is &HFF000000.

dim p as new picture(me.width,me.Height,32) me.DrawInto(p.graphics,0,0) me.Backdrop = p msgbox str(p.RGBSurface.Pixel(10,10))
I guess the best route would be to use BitBlt to grab a screen shot, then use RGBSurface.Pixel on the obtained picture to get the color of the window.

BitBlt declare method posted in https://forum.xojo.com/12170-printwindow-api

Thanks Michel,

I’ve been looking at getting the values from the registry, HKEY_Current_user\Control Panel\Colours
it seems that the window is being drawn with the buttonface colour
its either that or Menu/MenuBar

so i think thats probably the best way of getting it.

well it works, sort of!

the next issue is that my dojo window doesn’t redraw when the user changes the windows theme,
you have to make the window redraw.

any ideas?

[quote=117591:@Russ Lunn]well it works, sort of!

the next issue is that my dojo window doesn’t redraw when the user changes the windows theme,
you have to make the window redraw.

any ideas?[/quote]

self.invalidate ?

well, yes, but how do i know that the user has changed the system colours?

Monitor RegistryItem(“HKEY_Current_user\Control Panel\Colours”) with a timer and if the value change refresh the window ? But the user does not change the window color all the time.

Or do it by monitoring TaskList for the Control Panel application and when it stops, assume the color could have been changed.

If would be better to actually know when the screen is changed, but there does not seem to be an event available. Maybe through the API ?

actually, my window is changing correctly, without any intervention but my listbox (which is where I’m changing the colour in backgroundpaint) isn’t.

I don’t understand.

[quote=117588:@Russ Lunn]Thanks Michel,

I’ve been looking at getting the values from the registry, HKEY_Current_user\Control Panel\Colours
it seems that the window is being drawn with the buttonface colour
its either that or Menu/MenuBar

so i think thats probably the best way of getting it.[/quote]

Why not use FillColor instead? That would take care of it for you, no matter what the user had set as the system defaults.

I think on the contrary, Russ wants to get the color the user has selected. But he went unclear afterward.

But FillColor gets the color that the user has selected through the control panel - the system window color. I think that’s what he’s after?

A simple declare works:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724371(v=vs.85).aspx

Using the index you can obtain any item’s “theme” color (in case the user changed it).

Declare Function GetSysColor Lib “user32” Alias “GetSysColor” (nIndex As Integer) As Integer

And call it as such:
Dim winColor as Variant
winColor = GetSysColor(5)
return winColor.ColorValue

If you want to change the background color of your listbox, you’ll need to do so in the CellBackgroundPaint event.

i think I’ve confused everyone. :wink:

i have a window with a listbox.
the listbox CellBackgroundPaint event, gets the system colour (using registry, but soon to be the declare, thanks Matthew)

that all works.

then the user changes theme and my window changes its colour automatically, but the listbox stays at the previous colour
It seems that when the theme changes my window was told to refresh itself, which it did, but it didn’t tell the listbox to refresh

this leaves some very funky things on the screen :wink:

You try Listbox.Invalidate () ?

There’s also APIs to

Lock/Unlock the GUI between refreshes… used if you see line/outline remnants after a refresh, and makes the transition appear instantly without lag of ‘refresh.’

sorry Matthew,

i know that listbox.invalidate will redraw the listbox, but where do i call it from?

i tried window1.paint but it didn’t work.

You can keep track using a timer of the background color, and if it has changed cask the refresh.

I’d personally use a window hook and hook into the Windows Message System (WMS) to capture the window refresh event as it happens.

Without being able to access my laptop at the moment, I can’t whip up an example, but I can at least direct you to these links. They use VB6; the syntax is moreso Xojo friendly than other languages.

http://www.thescarms.com/VBasic/subclassform.aspx

http://support.microsoft.com/kb/170570

They should provide a general idea of the hooking procedure, but the message from the WindowProc you are actually looking to capture is:

WM_Paint

http://msdn.microsoft.com/en-us/library/windows/desktop/dd145213(v=vs.85).aspx

This is also the method to induce window events not normally supported by Xojo.