C++ Builder

La Isla Bonita



Polygon Function (Win32 API)
Polygon Function (Win32 API)


Description

This example shows how to use the Polygon() function which is part of the Win32 API's

Form1 contains a TButtons and a TPaintBox component.

Files

Polygon.cpp

#include <vcl.h>
#pragma hdrstop

#include "Polygon.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

POINT Poligon1[2]  = {{50, 150}, {150, 20}};
POINT Poligon2[4]  = {{0,0}, {200, 200}, {100, 200}, {0,0}};
CONST POINT *pPoints1 = &Poligon1[0];
CONST POINT *pPoints2 = &Poligon2[0];

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    //Paint on the Form's Canvas Property
    //
    Canvas->Pen->Color = clRed;
    Polygon( Canvas->Handle, pPoints1, 2);  //Win32 API

    Canvas->Pen->Color = clBlue;
    Polygon( Canvas->Handle, pPoints2, 4);  //Win32 API
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
    //Paint on the TPaintBox's Canvas Property
    //
    ((TPaintBox *)Sender)->Canvas->Pen->Color = clRed;
    Polygon( ((TPaintBox *)Sender)->Canvas->Handle, pPoints1, 2);  //Win32 API

    ((TPaintBox *)Sender)->Canvas->Pen->Color = clBlue;
    Polygon( ((TPaintBox *)Sender)->Canvas->Handle, pPoints2, 4);  //Win32 API
}
//---------------------------------------------------------------------------

Polygon.h

#ifndef PolygonH
#define PolygonH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
        TButton *Button1;
        TPaintBox *PaintBox1;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall PaintBox1Paint(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.