# MAKEPOINTS structure (win32)

• 12-22-2004
codegeek
MAKEPOINTS structure (win32)
I'm very new to C++ and am confused with how the MAKEPOINT structure works.
Quote:

POINTS MAKEPOINTS(
DWORD dwValue // coordinates of a point
);
The definition of dwValue is as follows:
Quote:

Specifies the coordinates of a point. The x-coordinate is in the low-order word, and the y-coordinate is in the high-order word.
What are low and high order words? How do I create an instance of MAKEPOINTS with 10, 10?

• 12-22-2004
anonytmouse
If you want a POINTS struct with 10, 10 just do it like any other structure:
Code:

```POINTS pts; pts.x = 10; pts.y = 10;```
or, even easier:
Code:

`POINTS pts = { 10, 10 };`
The MAKEPOINTS macro is a helper macro that can be used with certain window messages. For example the WM_RBUTTONDOWN passes an x, y value in the lParam:
Quote:

Originally Posted by MSDN WM_RBUTTONDOWN
lParam
The low-order word(the lower 16 bits) specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

The high-order word(the upper 16 bits) specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

Now, instead of extracting the x,y values manually, we can just use the MAKEPOINTS macro.
Code:

```int x = MAKEPOINTS(lParam).x; int y = MAKEPOINTS(lParam).y;```
• 12-22-2004
Sebastiani
it's not a structure, it's a macro that cast a pointer to a 4 byte integer into a pointer to a POINTS structure (consisting of 2, 2 byte integers).

>> #define MAKEPOINTS(l) (*((POINTS FAR *)&(l)))

it's mainly useful for when your window procedure passes you coordinates in the LPARAM variable.

you can make your own variable like: LPARAM p = MAKELONG(x, y);

note that the cast is guaranteed to work since the POINTS structure is aligned to single-byte boundaries - other structures you must be careful with similar cast hacks.

foiled!
[/edit]