C++ Builder

La Isla Bonita



How to change the system colors on Windows CE
How to change the system colors on Windows CE


Description

This example illustrates how to change the system colors though the Win32 API function: SetSysColors(). This function is only available on the Windows CE operating system.

This function has the following syntax

BOOL WINAPI SetSysColors(
          int NumberOfElements,      // number of elements to change
          CONST INT* pElements,	     // address of array of elements
          CONST COLORREF* pRGBValues // address of array of RGB values
          );
Note that the color change performed through this function will only apply to the Windows session in which the function was invoked. Thus, color changes obtained via SetSysColors are temporary.

Files

SysColors.cpp

#include <vcl.h>
#pragma hdrstop
#include "SysColors.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  CONST INT Elements[]  = {
    COLOR_3DDKSHADOW,	 
    COLOR_3DFACE,        
    COLOR_BTNFACE,
    COLOR_3DHILIGHT, 
    COLOR_3DLIGHT,	 
    COLOR_3DSHADOW,  
    COLOR_ACTIVEBORDER,	 
    COLOR_ACTIVECAPTION, 
    COLOR_APPWORKSPACE,	 
    COLOR_BACKGROUND,    
    COLOR_BTNTEXT,	     
    COLOR_CAPTIONTEXT,	 
    COLOR_GRAYTEXT,	     
    COLOR_HIGHLIGHT,	 
    COLOR_HIGHLIGHTTEXT, 
    COLOR_INACTIVEBORDER,
    COLOR_INACTIVECAPTION,
    COLOR_INACTIVECAPTIONTEXT,
    COLOR_INFOBK,	     
    COLOR_INFOTEXT,	     
    COLOR_MENU,	         
    COLOR_MENUTEXT,      
    COLOR_SCROLLBAR,	 
    COLOR_WINDOW,	     
    COLOR_WINDOWFRAME,	 
    COLOR_WINDOWTEXT
    };

CONST COLORREF RGBColor[][3]  = {{255, 100,  20}, //1
                                 {100,  50, 120}, //2
                                 {120, 130, 170}, //3
                                 {10,   10,  70}, //4
                                 { 70,   1,  44}, //5
                                 {110,  10,  33}, //6
                                 {60,   75,  17}, //7
                                 { 10,  20,  30}, //8
                                 {150, 200, 135}, //9
                                 {  0, 256,  25}, //10
                                 {100, 200, 200}, //11
                                 {128, 128, 254}, //12
                                 { 80,  80,  80}, //13
                                 {100, 100,  70}, //14
                                 {  0, 125,  44}, //15
                                 {110,  10,  33}, //16
                                 { 60,  60, 170}, //17
                                 {100, 200, 100}, //18
                                 {150, 200,  50}, //19
                                 { 25, 100, 100}, //20
                                 {  1,   2, 100}, //21
                                 {175,  20,  50}, //22
                                 { 30, 105,   0}, //23
                                 {100,  50, 225}, //24
                                 {220, 125,  44}, //25
                                 {110, 100,  35}  //26
                                };

    CONST INT* pElements = &Elements[0];
    CONST COLORREF* pRGBColor = &RGBColor[0][0];

    if (SetSysColors(ARRAYSIZE(Elements), pElements, pRGBColor))
        ShowMessage("Success: Colors have been changed");
    else
        ShowMessage("Failure: Colors cannot be changed");
}
//---------------------------------------------------------------------------

SysColors.h

#ifndef SysColorsH
#define SysColorsH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TButton *Button1;
        TSpeedButton *SpeedButton1;
        TScrollBox *ScrollBox1;
        TImage *Image2;
        void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Homepage

Copyright © 1997-2003 Rodolfo A. Frino. All rights reserved.