?
Solved

Setting and Restoring System Colors

Posted on 2003-02-19
13
Medium Priority
?
1,267 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:Rah082800
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
13 Comments
 
LVL 2

Expert Comment

by:AFI
ID: 7983419
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
 

Author Comment

by:Rah082800
ID: 7984157
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
 
LVL 2

Expert Comment

by:AFI
ID: 7985253
SetSysColors and GetSysColors applies and get the change of color immediately. RegistrySet, if change may be you need to reboot.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:buasuwan
ID: 7986741
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
 

Author Comment

by:Rah082800
ID: 7987412
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
 

Author Comment

by:Rah082800
ID: 7988841
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
 
LVL 2

Expert Comment

by:AFI
ID: 7989001
Show me you SetSysColors external declaration and script to help you.
0
 

Author Comment

by:Rah082800
ID: 7989333
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
 
LVL 2

Expert Comment

by:AFI
ID: 7989561
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
 

Author Comment

by:Rah082800
ID: 7989962
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
 

Author Comment

by:Rah082800
ID: 7990201
Adding this to script:
messagebox("SetSysColors","Failed" + string(GetLastError()))

GetLastError gives me 998
0
 
LVL 5

Accepted Solution

by:
buasuwan earned 800 total points
ID: 7994383
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
 

Author Comment

by:Rah082800
ID: 7995254
To: buasuwan

Thank You - Thank You - Thank You

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

Rah
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question