Using Win32 functions in Visual FoxPro Image Gallery
System Information
..msdn
ExpandEnvironmentStrings
GetComputerName
GetComputerNameEx
GetComputerObjectName
GetCurrentHwProfile
GetKeyboardType
GetNativeSystemInfo
GetProductInfo
GetSysColor
GetSystemDirectory
GetSystemInfo
GetSystemMetrics
GetSystemRegistryQuota
GetSystemWow64Directory
GetUserName
GetUserNameEx
GetVersion
GetVersionEx
GetWindowsDirectory
IsNetworkAlive
SetComputerName
SetSysColors
SystemParametersInfo
Code examples:
Changing system colors
Changing system colors

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The code sample changes colors of the window background and active caption for any window bothering to listen for the WM_SYSCOLORCHANGE message broadcasted by the SetSysColors function.

After running this code sample, you will notice that colors changed in all windows through the OS. That includes even controls like textboxes and comboboxes. Note that the native VFP controls are not windows like for example VB.NET controls. But they do closely follow the system colors when they draw themselves.

Do not panic and find below how to restore the colors back to their original values.
 
* note: to reverse the system colors back to normal 
* release the oColorTest variable
 
PUBLIC oColorTest As TColorTest
oColorTest = CREATEOBJECT("TColorTest")
oColorTest.ChangeColors
* end of main
 
DEFINE CLASS TColorTest As Session
PROTECTED ColorMask, SavedColors, NewColors
 
PROCEDURE Init
    THIS.declare
 
PROCEDURE ChangeColors
#DEFINE COLOR_SCROLLBAR 0
#DEFINE COLOR_ACTIVECAPTION 2
#DEFINE COLOR_WINDOW 5
#DEFINE COLOR_WINDOWFRAME 6
#DEFINE COLOR_MENUTEXT 7
#DEFINE COLOR_WINDOWTEXT 8
    * colors for these two elements are to be 
    * changed and eventually restored back
    THIS.ColorMask = num2dword(COLOR_WINDOW)+;
        num2dword(COLOR_ACTIVECAPTION)
 
    * the original colors are saved in the class property
    THIS.SavedColors = num2dword(GetSysColor(COLOR_WINDOW))+;
        num2dword(GetSysColor(COLOR_ACTIVECAPTION))
 
    * changing the colors
    THIS.NewColors = num2dword(RGB(128,192,230))+;
        num2dword(RGB(192,0,192))
 
    = SetSysColors(2, THIS.ColorMask, THIS.NewColors)
 
PROCEDURE Destroy
* making sure that upon releasing the instance
* of the class all colors are restored back
    THIS.RestoreColors
 
PROCEDURE RestoreColors
    = SetSysColors(2, THIS.ColorMask, THIS.SavedColors)
 
PROCEDURE declare
    DECLARE INTEGER GetSysColor IN user32 INTEGER nIndex
 
    DECLARE INTEGER SetSysColors IN user32;
        INTEGER nElements, STRING lpSysColor,;
        STRING lpColorValues
 
ENDDEFINE
 
FUNCTION num2dword(lnValue)
#DEFINE m0 0x0000100
#DEFINE m1 0x0010000
#DEFINE m2 0x1000000
    IF lnValue < 0
        lnValue = 0x100000000 + lnValue
    ENDIF
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
 

User rating: 10/10 (2 votes)
Rate this code sample:
  • ~
1754 bytes  
Created: 2001-07-14 12:00:00  
Modified: 2009-01-07 12:02:23  
Visits in 7 days: 77  
Listed functions:
GetSysColor
SetSysColors
Printer friendly API declarations
My comment:
The code is written in what can be called a safe way -- the system colors are restored back to original values when the instance of the TColorTest class is released. Type CLEAR ALL in the Command Window or simply close the Visual FoxPro to do that.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (50.16.36.153)
3 sec.
Function group: 'National Language Support'
38.32 min.Example: 'Enumerating the subkeys for a given registry key'
38.38 min.Example: 'Form Magnifier'
57.82 min.Example: 'Creating the Open dialog box to specify the drive, directory, and name of a file to open'
57.88 min.Example: 'Validating the heap of the calling process'
1.07 hrs.Example: 'How to change the name and the size of the font in the MessageBox dialog'
 Example: 'Minimizing all running applications'
1.08 hrs.Function: 'GetObjectType'
Function group: 'Device Context'
2.54 hrs.Example: 'How to make a VFP form fading out when released (GDI version)'
4.08 hrs.Function: 'CreateProcessAsUser'
Function group: 'Process and Thread'
Google
Advertise here!