//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ColorToRGB.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: ColorToRGB
// Routine: Graphics.ColorToRGB

// BeginCode
/*
The following code converts the color of the current form,
Form1, to a Windows RGB value:
*/
int NumPaletteEntries = 20;
TPaletteEntry FPaletteEntries[20];

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, NumPaletteEntries,
	FPaletteEntries);
  Form1->Color = clMoneyGreen;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int Result = 0;
  int I = 0;
  TColor RealColor = Graphics::ColorToRGB(Form1->Color);
  while (I < NumPaletteEntries)
  {
//  with FPaletteEntries[I] do
	TColor paletteColor =
	RGB(
	  FPaletteEntries[I].peRed,
	  FPaletteEntries[I].peGreen,
	  FPaletteEntries[I].peBlue);
	if (RealColor == paletteColor)
	{
	  Label1->Caption = IntToStr(I);
	  RedEdit->Text = IntToStr(FPaletteEntries[I].peRed);
	  GreenEdit->Text = IntToStr(FPaletteEntries[I].peGreen);
	  BlueEdit->Text = IntToStr(FPaletteEntries[I].peBlue);
	  break;
	}
	I++;
  };
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Form1->Color =
	(StrToInt(RedEdit->Text) << 16) +
	(StrToInt(GreenEdit->Text) << 8) +
	(StrToInt(BlueEdit->Text));
}
// EndCode
// EndExample: ColorToRGB
//---------------------------------------------------------------------------
