CONNECT uses an array of POINT structures for saving points. The POINT structure is defined in WINDOWS.H and has two fields named x and y:
typedef struct tagPOINT
{
int x ;
int y ;
} POINT ;
Some Windows functions require a POINT structure (or a pointer to a POINT structure) as a parameter. You can define a POINT structure variable (named point, for instance) in your program with this definition:
POINT point ;
If you need to convert an lParam value—the x and y mouse coordinates—to a POINT structure, you can use the MAKEPOINT macro:
point = MAKEPOINT (lParam) ;
In WINDOWS.H, MAKEPOINT is defined like this:
#define MAKEPOINT(l) (*((POINT *)&l))
Despite the apparent complexity of this macro, it compiles very efficiently because all it does is store lParam at the address of point. WINDOWS.H defines the type PPOINT as a pointer to a POINT structure, so perhaps this statement (without using the macro) makes the conversion a little clearer:
point = * (PPOINT) &lParam ;
(Remember that standard C order-of-evaluation rules cause address, indirection, and type cast operators to be evaluated from right to left.)
The RECT structure defines a rectangle. Here's the WINDOWS.H definition:
typedef struct tagRECT
{
int left ;
int top ;
int right ;
int bottom ;
} RECT ;
This structure really contains two points side by side: left and right are x-coordinates, and top and bottom are y-coordinates. You can define a structure variable (named rect, for instance) with the statement:
RECT rect ;
Transferring coordinates from a RECT structure to a POINT structure is also straightforward. This statement sets point to the upper left corner of the rectangle:
point = * (PPOINT) &rect.left ;
This does the same for the lower right corner:
point = * (PPOINT) &rect.right ;
You can also define an array of two points:
POINT points [2] ;
and transfer these two points into a RECT structure:
rect = * (PRECT) points ;
PRECT is defined in WINDOWS.H as a pointer to a RECT structure. You don't need the & (address) operator before points because points is an array. In C, an array name is the address of the first element of the array.