先看看MSDN的说明:
RECT Structure
The RECT data structure has the following form:
typedef struct tagRECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.
Members
left
Specifies the x-coordinate of the upper-left corner of a rectangle.
top
Specifies the y-coordinate of the upper-left corner of a rectangle.
right
Specifies the x-coordinate of the lower-right corner of a rectangle.
bottom
Specifies the y-coordinate of the lower-right corner of a rectangle.
翻译一下:
RECT结构定义一个矩形的左上角和右下角的坐标
成员
left 指定矩形左上角的X坐标
top指定矩形左上角的Y坐标
right指定矩形右下角的X坐标
bottom指定矩形右下角的Y坐标
看起来很精确了,但是实际使用中还不是那么如意,我在进行图片衔接绘制背景的时候,经常出现一个像素的接缝!!!
于是研究了一下,才发现这所谓的坐标其实还是有猫腻的,先看下MFC的CRect
CRect是对RECT的封装,可以直接用
RECT rc1;
CRect rc = rc1;
CRect有求宽度和高度的成员函数,如CRect::Width(),在MSDN的解释是:
Calculates the width of CRect by subtracting the left value from the right value. The width can be negative.
翻译一下:
用right值减去left值来计算CRect的宽度, 宽度可能是负值.
如果说屏幕坐标中,坐标是0开始的,那么一个100x100的Rect其值应为
RECT rc = {0, 0, 99, 99};
那么right-left=99-0=99怎么会得到100呢?因此要么MFC是狗娘养的,要么MSDN是杂种.
调用GetWindowRect对得到的数据分析,其结果是right和bottom是右下角对顶点的坐标:
如图是一个有WS_CHILD风格的子窗口,其RECT是{25, 21, 58, 54};
大小为33x33像素!