Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.

One of the beautiful things of windows applications is that they immediately apply any user settings. The setback of VFP apps is that the _screen.background color is white until you change it programmatically. One way of working around that is NOT using the _screen object and define your own background screen but I always considered that working the hard way around. What I tried to achieve is that my _screen.background is adjusted automatically whenever the users want to change the application background color through the windows properties.

About the application background color
Right-clicking the desktop brings up the popup from where you can choose the “properties” item. Clicking the “Appearance” tab brings the following dialog:

If you click the Item dropdown list you can find the “Application Background” item. With the Color dropdown list you can pick a color that will be the new background color for most of your apps, “most” because the VFP apps we use to write are not automatically adjusted. I wanted my apps to act according to any change in the system applied by the user.

Sysinfo activeX to the rescue
Microsoft created, quite a long time ago, a nifty control to retrieve info about the system. This control is the sysinfo.ocx, an activeX control that is installed on your machine whenever you install VFP. There are many interesting methods that are fired whenever something in the system changes. The method I found is the SysColorsChanged event. This method is fired every time the system colors are changed by the user.

GetSysColor to the rescue
Retrieving the backcolor from the system requires an easy to do API call. We need the GetSysColor function for that. The full syntax for that function is:

DECLARE Integer GetSysColor IN WIN32API Integer

GetSysColor retrieves a color and gives that back as an Integer. The color it retrieves is based on what you want to do. A value of 12 retrieves the Application Background.
Remarkably here is that all the other components of VFP applications do react automatically to any change in colors without the programmer having to interfere. My thought about this is that the white background is easy to use for the developer. Displaying results in black letters on a white background is easier to read than black letters on a dark gray background that would look like this. Black letters on Dark Gray. Not really what I would like. After all, when writing an article in Word we also use a white background. However, the application background of word is, in my case, dark gray.

While working with this I thought it would be easy to create a class of the sysinfo ActiveX control and add that to the _screen object.
I created the class, in the SysColorsChanged Event I placed some code to retrieve the desired background color and I stored it in a classlib. I created a _screen.property oSysInfo and wanted to add an object of the sysinfo control to it. That did not work.

The solution

Adding the control to a form works fine. The form has 2 methods filled in. Init and a custom method, GetScreenColor. The init has the following code:

this.Visible = .F.

On the form is the sysinfo control, renamed from oleobject1 to sysinfo. In the 3rd line of the code that control is called. Finally I make sure the form loses focus to give control back where it should be, with the user. The GetScreenColor method has the following code:

LOCAL lnColor
lnCoLor = GetSysColor(tnColorType)

It basically retrieves the Application background color and returns the value from that. As you can see in the code for the INIT of the form the sysColorsChanged event from sysinfo is called, here is the code:

_screen.backcolor = thisform.GetScreenColor(12)

As you can see, it is very simple, it calls the GetScreenColor from the form and applies the returned value to the _screen.backcolor.

Making it work
This class (sysinfo) is stored in the sysinfo classlib. So here is the code to make things work:

Set classlib to sysinfo additive

If you make any changes to the application background color through the property dialog as described above these changes are reflected immediately in your applications.



Boudewijn Lutgerink Programming is one of the many hobbies of Boudewijn. He has worked with computers since 1985 and is the author of two books from Sybex. He has a weblog at http://weblogs.foxite.com/boudewijnlutgerink.


Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: