Windows POINT,RECT,SIZE结构体封装:
typedef struct tagPOINT { LONG x; LONG y; }POINT,*PPOINT; typedef struct tagSIZE { LONG cx; LONG cy; }SIZE,*PSIZE; typedef struct _RECT { LONG left,right; LONG top,bottom; }RECT,*PRECT;(1)CPoint 类
CPoint(int initX,int initY); CPoint(POINT initpt);(2)CSize类
CSize(int initCX,int init CY); CSize(SIZE initSize);(3)CRect类
CRect(int l,int t,int r,int b); CRect(const RECT& srcRect);//srcRect是一个RECT结构 CRect(LPCRECT lpSrcRect);//lpSrcRect是一个RECT结构指针 CRect(POINT point,SIZE size);//point是左上角 CRect(POINT topLeft,POINT bottomRight);设置窗口原点函数
CPoint SetWindowOrg(int x,int y); CPoint SetWindowOrg(POINT point);设置视区原点函数
virtual CPoint SetViewportOrg(int x,int y); virtual CPoint SetViewportOrg(POINT point);理解“窗口”、“视区” 根据“窗口”,“视区”的大小可以确定x方向和y 方向的比例 SetWindowExt(100,100); SetViewportExt(200,200); 100X100逻辑坐标的正方形—>200X200像素的正方形
设置一个原点位于中心的二维坐标:
CRect rect;//声明对象 GetClientRect(&rect);//获得客户区大小?? //设置映射模式 pDC->SetMapMode(MM_ANISOTROPIC); //设置窗口 pDC->SetWindowExt(rect.Width(),rect.Hieght()); //设置视区(共同确定映射比例因子) //负号改变正方向 pDC->SetViewportExt(rect.Width(),-rect.Height()); //设置中心为原点 pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);