Setting and Restoring System Colors

Is there a way to set the system colors when the powerbuilder program starts and then return the system colors to the users at the end of the program?
Rah082800Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AFICommented:
Hello.

//External
Function ulong GetSysColor (int index) Library "USER32.DLL"

//Function return ulong
Return GetSysColor (ai_index)

//Value of ai_index
/*
Value     Meaning
COLOR_3DDKSHADOW     Dark shadow for three-dimensional display elements.
COLOR_3DFACE,
COLOR_BTNFACE     Face color for three-dimensional display elements.
COLOR_3DHILIGHT, COLOR_3DHIGHLIGHT, COLOR_BTNHILIGHT, COLOR_BTNHIGHLIGHT     Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DLIGHT     Light color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DSHADOW, COLOR_BTNSHADOW     Shadow color for three-dimensional display elements (for edges facing away from the light source).
COLOR_ACTIVEBORDER     Active window border.
COLOR_ACTIVECAPTION     Active window caption.
COLOR_APPWORKSPACE     Background color of multiple document interface (MDI) applications.
COLOR_BACKGROUND, COLOR_DESKTOP     Desktop.
COLOR_BTNTEXT     Text on push buttons.
COLOR_CAPTIONTEXT     Text in caption, size box, and scroll bar arrow box.
COLOR_GRAYTEXT     Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color.
COLOR_HIGHLIGHT     Item(s) selected in a control.
COLOR_HIGHLIGHTTEXT     Text of item(s) selected in a control.
COLOR_INACTIVEBORDER     Inactive window border.
COLOR_INACTIVECAPTION     Inactive window caption.
COLOR_INACTIVECAPTIONTEXT     Color of text in an inactive caption.
COLOR_INFOBK     Background color for tooltip controls.
COLOR_INFOTEXT     Text color for tooltip controls.
COLOR_MENU     Menu background.
COLOR_MENUTEXT     Text in menus.
COLOR_SCROLLBAR     Scroll bar gray area.
COLOR_WINDOW     Window background.
COLOR_WINDOWFRAME     Window frame.
COLOR_WINDOWTEXT     Text in windows.
*/

/*
The SetSysColors function sets the colors for one or more display elements. Display elements are the various parts of a window and the Windows display that appear on the system display screen.

BOOL WINAPI SetSysColors(

    int cElements,     // number of elements to change
    CONST INT *lpaElements,     // address of array of elements
    CONST COLORREF *lpaRgbValues      // address of array of RGB values  
   );    
 

Parameters:

cElements
Specifies the number of display elements in the array pointed to by the lpaElements parameter.

lpaElements
Points to an array of integers that specify the display elements to be changed. For a list of display elements, see the GetSysColor function.

lpaRgbValues
Points to an array of unsigned long integers that contains the new red, green, blue (RGB) color value for each display element in the array pointed to by the lpaElements parameter.

Return Values

If the function succeeds, the return value is nonzero.
*/
0
Rah082800Author Commented:
Can I use RegistrySet?  This command changes the values in Regedit, however, they do not apply to the PB window.  Is there another command that needs to execute before the color change is applied?
0
AFICommented:
SetSysColors and GetSysColors applies and get the change of color immediately. RegistrySet, if change may be you need to reboot.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

buasuwanCommented:
Hi Rah,
   If you already set all sys-color in Registry.
You need to boardcast message to all windows to see effects.
here is script

Post(-1, 21, 0, 0)

0
Rah082800Author Commented:
Here is the code I have added to the Open script of the powerbuilder window.
RegistrySet("HKEY_CURRENT_USER\Control Panel\Colors", "ButtonFace", RegString!, "255 255 0")

This should change the buttonface color to yellow however it stays the original system color of gray.  In RegEdit the values have been changed for the button face property.  Adding a line with Post(-1, 21, 0, 0) to the script did not change the screen.  What is the proper syntax and what do the parameters indicate?

After I do the registryset command, then reboot, the colors change.  I do not want the user to reboot.
0
Rah082800Author Commented:
One more observation:
When I try the SetSysColors options the compiler gives me an unknown function error.  Am I missing an add on or something?
0
AFICommented:
Show me you SetSysColors external declaration and script to help you.
0
Rah082800Author Commented:
I attempted to follow your above script:
//External
int index
Function ulong SetSysColor(index) Library "USER32.DLL"

int COLOR_BTNFACE, COLOR_WINDOW

int aiElements[2] = {COLOR_BTNFACE, COLOR_WINDOW};

// Array of RGB values.
long aColors[2];
 
// Define the new colors.
 
aColors[0] = RGB(141 156 197);
aColors[1] = RGB(186 194 217);

// Set the window elements in aiElements to the colors
// specified in aColors.
 
boolean winapi SetSysColors(2, aiElements, aColors);

Syntax errors appear on function and boolean winapi lines.
Do not assume I should know where this code is placed and that I have all items set up correctly.  I need basic step by step instructions.

Thanks
0
AFICommented:
Ok... the GetSysColor is in PB language, the SetSysColor was in Win32 SDK... The following is the PB external declaration:

Function Long SetSysColors (Long nChanges, LonglpSysColor, Long lpColorValues) Library "user32"

//Script

Constant int COLOR_SCROLLBAR = 0 //The Scrollbar colour
Constant int COLOR_BACKGROUND = 1 //Colour of the background with no wallpaper
Constant int COLOR_ACTIVECAPTION = 2 //Caption of Active Window
Constant int COLOR_INACTIVECAPTION = 3 //Caption of Inactive window
Constant int COLOR_MENU = 4 //Menu
Constant int COLOR_WINDOW = 5 //Windows background
Constant int COLOR_WINDOWFRAME = 6 //Window frame
Constant int COLOR_MENUTEXT = 7 //Window Text
Constant int COLOR_WINDOWTEXT = 8 //3D dark shadow (Win95)
Constant int COLOR_CAPTIONTEXT = 9 //Text in window caption
Constant int COLOR_ACTIVEBORDER = 10 //Border of active window
Constant int COLOR_INACTIVEBORDER = 11 //Border of inactive window
Constant int COLOR_APPWORKSPACE = 12 //Background of MDI desktop
Constant int COLOR_HIGHLIGHT = 13 //Selected item background
Constant int COLOR_HIGHLIGHTTEXT = 14 //Selected menu item
Constant int COLOR_BTNFACE = 15 //Button
Constant int COLOR_BTNSHADOW = 16 //3D shading of button
Constant int COLOR_GRAYTEXT = 17 //Grey text, of zero if dithering is used.
Constant int COLOR_BTNTEXT = 18 //Button text
Constant int COLOR_INACTIVECAPTIONTEXT = 19 //Text of inactive window
Constant int COLOR_BTNHIGHLIGHT = 20 //3D highlight of button
Constant int COLOR_2NDACTIVECAPTION = 27 //Win98 only: 2nd active window color
Constant int int COLOR_2NDINACTIVECAPTION = 28 //Win98 only: 2nd inactive window color

SetSysColors(1, COLOR_ACTIVECAPTION, RGB(255, 0, 0))
0
Rah082800Author Commented:
Ok..We are making progress..
I declared the external function.  Put all the constants in the script and added:
 if SetSysColors(1, COLOR_BTNFACE, RGB(141,156,197)) = 0 then
     messagebox("SetSysColors","Failed")
end if

I get the messagebox SetSysColors Failed.  
How do I find out why it failed?
0
Rah082800Author Commented:
Adding this to script:
messagebox("SetSysColors","Failed" + string(GetLastError()))

GetLastError gives me 998
0
buasuwanCommented:
Sorry for interuption.

I saw the wrong External function declaration.
this should be.

Function Long SetSysColors (Long nChanges, ref Long lpSysColor[], ref Long lpColorValues[]) Library "user32"


and your scripts should be changed to.
// declaraions

Constant long COLOR_BTNFACE = 15 //Button
Constant long COLOR_WINDOW = 5 //Windows background

// and scripts
long     ll_syscolor[]
ll_syscolor[1] = COLOR_BTNFACE
ll_syscolor[2] = COLOR_WINDOW

long     ll_color_values[]
ll_color_values[1] = RGB(255,255,0)  
ll_color_values[2] = RGB(255,0,0)  


SetSysColors (2, ll_syscolor, ll_color_values)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rah082800Author Commented:
To: buasuwan

Thank You - Thank You - Thank You

This finally works.  You don't know how much time you saved me.

Rah
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.