Programming With Microsoft Visual Studio C++.NET 6th Edition 读书笔记(1) Chapter 5: Windows Message Mapping

Chapter 5: Windows Message Mapping
CRect, CPoint, and CSize Arithmetic
The CRect, CPoint, and CSize classes are derived from the Windows RECT, POINT, and SIZE structures, and thus they inherit public integer data members, as follows:

CRect
left, top, right, bottom
CPoint
x, y
CSize
cx, cy

If you look in the MFC Library Reference, you'll see that these three classes have a number of overloaded operators. You can, among other things, do the following:
  • Add a CSize object to a CPoint object
  • Subtract a CSize object from a CPoint object
  • Subtract one CPoint object from another, yielding a CSize object
  • Add a CPoint or CSize object to a CRect object
  • Subtract a CPoint or CSize object from a CRect object
The CRect class has member functions that relate to the CSize and CPoint classes. For example, the TopLeft member function returns a CPoint object, and the Size member function returns a CSize object. From this, you can begin to see that a CSize object is the "difference between two CPoint objects" and that you can "bias" a CRect object by a CPoint object.
 
GetClientRect
The following view member function code retrieves the client rectangle coordinates and stores them in rectClient:
 
CRect rectClient;
GetClientRect(rectClient);
 
Determining Whether a Point Is Inside an Ellipse
CRgn rgn;
rgn.CreateEllipticRgnIndirect(&m_rectEllipse);
if(rgn.PtInRegion(point))
{
         m_nColor = GRAY_BRUSH;
}
else
{
         m_nColor = BLACK_BRUSH;
}
 
Using Windows Mapping Modes
setWindowOrg 改变坐标原点的位置,例如可以setWindowOrg(100,100) 那么窗口左上点就是100,100
 
按习惯,(0,0)就原点,原点就是(0,0),但是如果用此来理解windows的map mode,就会走弯路。其实,稍微改变一下观念,windows的map mode就比较好理解了。举例说明:
 
page space---->device space
pDC->SetMapMode(MM_LOMETRIC);
pDC->SetWindowOrg(40,0);  //这句“设定”page space的原点为(40,0),注意,
//这时(40,0)就是原点,原点就是(40,0)这个点,其实,(0,0)与原点没有必然联系。这
//一句对下面的画图函数在page space中所作的图不会有任何影响。一句话:SetWindowOrg
//就是指定一下,page space中哪个点为原点。
pDC->Rectangle(0,0,100,-100);
pDC->Rectangle(0,-100,50,-200);
 
同理,SetViewportOrg也是指定一下,device space中哪个点为原点,两个坐标系映射时,两个原点重合。
 
SetWindowExt设定page space的大小,SetViewportOrg设定device space的大小,其实,真正有意义的只是两者的比例关系,例如,在一个1024*768的显示屏上:
 
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(10240,7680);
pDC->SetViewportExt(1024,768);
pDC->Rectangle(0,0,100,100);
 
  就会画一个10 pixels*10 pixels的矩形。其本质就是,X方向,每个逻辑单位有1024/10240个象素,Y方向每个逻辑单位有768/7680个象素。因此,下面的代码有相同的作用:
 
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(102400,76800);
pDC->SetViewportExt(10240,7680);
pDC->Rectangle(0,0,100,100);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值