关于RECT结构体

先看看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像素!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值