Home

Accessories for Windows Controls: A Point

   

Introduction

To identify the concept of a point, the Win32 library provides the POINT structure. This structure is defined as follows:

typedef struct tagPOINT { 
	LONG x; 
	LONG y; 
} POINT, *PPOINT;
 

 The first member, x, represents the horizontal distance of the point from the top-left corner of the object that owns the point. The y member represents the vertical measurement of the point with regards to the top-left corner of the object that owns the point.

Besides the Win32's POINT structure, the VCL provides a class that performs the same operations with a more appropriate conception of a C++ class. It is called TPoint. While Win32 is written in C and most of its objects are pure structures in the C sense, the VCL's TPoint is a true and complete C++ class. It is defined as follows:

struct TPoint
{
	TPoint() {}
	TPoint(int _x, int _y) : x(_x), y(_y) {}
	TPoint(POINT& pt)
	{
		x = pt.x;
		y = pt.y;
	}
	operator POINT() const
	{
		POINT pt;
		pt.x = x;
		pt.y = y;
		return pt;
	}
	int x;
	int y;
};

As you can see, you can define or retrieve the position of a TPoint variable using its x and y values. Because it has a constructor, you can also declare it as a C++ variable.

 
 
     
 

Home Copyright © 2010-2016, FunctionX