View Full Version : What Do The Numbers Stand For In The RECT Command?

December 25th, 2004, 02:42
Lines like this abound all thru the code and I guess I just have a mental block.

<bounds rect="WWW,XXX,YYY,ZZZ" />

I'm guessing:

WWW = Position from the left margin?
XXX = Position from the top margin?

What do the YYY and ZZZ stand for? :)

December 25th, 2004, 13:44
I'm not much of a coder, but google pointed me to this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/rectangl_6cqa.asp


The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

typedef struct _RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;


Specifies the x-coordinate of the upper-left corner of the rectangle.
Specifies the y-coordinate of the upper-left corner of the rectangle.
Specifies the x-coordinate of the lower-right corner of the rectangle.
Specifies the y-coordinate of the lower-right corner of the rectangle.


When RECT is passed to the FillRect function, the rectangle is filled up to, but not including, the right column and bottom row of pixels. This structure is identical to the RECTL structure.

Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Windef.h; include Windows.h.

December 27th, 2004, 14:43
I'll call them X, Y, W (for width) and H (for height).

X and Y are the coordinates of the top left corner of the element defined, respective to the top left corner of the sheet. W and H are the height and width. This is the basic case, but there are some exceptions to this.

You can make a control stick to each of the four corners of the sheet, or stretch to the size of the sheet.

If you make a number negative, it is calculated from the bottom (for Y and H) or right (for X and W) edge. For X and Y, this is pretty straightforward. However, if you specify a negative value in either the W or H position, it changes its meaning a bit, and is no longer a size measurement, but the actual point the control extends to, from the bottom or right edge. The vertical and horizontal coordinates work separately from each other, so you can make one direction stretch and use the basic form for the other.

Let's say you have a sheet 300 by 300 pixels, and want to position a control into it. Some examples:
10,10,40,30: The control starts 10 pixels from the top left corner in both directions, with a width of 40 pixels and a height of 30 pixels.
10,10,-10,-10: The control starts as above, but stretches all the way to 10 pixels from the bottom right corner. In this case, the control is 280 pixels high and wide.
-50,-40,40,30: The control is the same size as in the first example, but it sticks to the bottom right corner instead of the top left. The offset coordinates have to take into account both the desired offset, and the size.
10,10,-10,30: The control starts at 10,10 and stretches horizontally all the way to 10 pixels from the right edge. However, it is always 30 pixels high.