//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "PACSDK.h" #include "stdio.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; const int ORIGIN_X = 10; const int ORIGIN_Y = 40; const int GAP_SLOT = 30; const int UNIT_SLOT = 30; const int GAP_LABEL_SLOT = 5; int dipValue; TLabel * numbers[8]; TLabel * ON; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { ON = new TLabel(this); ON->Width = UNIT_SLOT; ON->Height = UNIT_SLOT / 2; ON->Left = ORIGIN_X; ON->Top = ORIGIN_Y - GAP_LABEL_SLOT - UNIT_SLOT / 2; ON->Font->Size =12; ON->Font->Style << fsBold; ON->Caption = "ON"; ON->Color = clRed; ON->Font->Color = clWhite; ON->Parent = Form1; //number Labels: for (int i = 0; i < 8; i++) { numbers[i] = new TLabel(this); numbers[i]->Width = UNIT_SLOT; numbers[i]->Height = UNIT_SLOT / 2; numbers[i]->Left = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i; numbers[i]->Top = ORIGIN_Y + (GAP_SLOT + UNIT_SLOT) * 2 + GAP_LABEL_SLOT; numbers[i]->Font->Size = 16; numbers[i]->Font->Style << fsBold; numbers[i]->Caption = IntToStr(i + 1); numbers[i]->Font->Color = clWhite; numbers[i]->Color = clRed; numbers[i]->Parent = Form1; } } //--------------------------------------------------------------------------- void __fastcall TForm1::paintDIP() { char dipstr[4]; //get DIP Value dipValue = pac_GetDIPSwitch(); Edit1->Text = IntToHex(dipValue, 2); //Red background TRect rect_red; rect_red.Left = ORIGIN_X; rect_red.Top = ORIGIN_Y; rect_red.Right = ORIGIN_X + 9 * GAP_SLOT + 8 * UNIT_SLOT; rect_red.Bottom = ORIGIN_Y + 2 * GAP_SLOT + 2 * UNIT_SLOT; Form1->Canvas->Brush->Color = clRed; Form1->Canvas->FillRect(rect_red); //White slots for (int i = 0; i < 8; i++) { TRect rect_white; rect_white.Left = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i; rect_white.Top = ORIGIN_Y + GAP_SLOT; rect_white.Right = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i + UNIT_SLOT; rect_white.Bottom = ORIGIN_Y + GAP_SLOT + UNIT_SLOT * 2; Form1->Canvas->Brush->Color = clWhite; Form1->Canvas->FillRect(rect_white); } //black slide for (int i = 0; i < 8; i++) { if (1 == ((dipValue >> i) & 1)) //ON { TRect rect_black; rect_black.Left = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i; rect_black.Top = ORIGIN_Y + GAP_SLOT; rect_black.Right = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i + UNIT_SLOT; rect_black.Bottom = ORIGIN_Y + GAP_SLOT + UNIT_SLOT; Form1->Canvas->Brush->Color = clBlack; Form1->Canvas->FillRect(rect_black); } else //OFF { TRect rect_black; rect_black.Left = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i; rect_black.Top = ORIGIN_Y + GAP_SLOT + UNIT_SLOT; rect_black.Right = ORIGIN_X + GAP_SLOT + (UNIT_SLOT + GAP_SLOT) * i + UNIT_SLOT; rect_black.Bottom = ORIGIN_Y + GAP_SLOT + UNIT_SLOT + UNIT_SLOT; Form1->Canvas->Brush->Color = clBlack; Form1->Canvas->FillRect(rect_black); } } Form1->Canvas->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { paintDIP(); } //---------------------------------------------------------------------------