我想实现这个:
把CMyView的逻辑坐标原点设置到窗口客户区的中点,x轴朝右,y轴朝上
并且让逻辑坐标系和设备坐标系的比例为2:1
然后画个坐标轴
接着再画一些矩形
因为这样会有闪烁,我就先把它画到内存,然后贴回来
但是不知道为什么总有问题
帮我看看代码有什么问题吧
代码如下:
void CMyView::OnDraw(CDC* pDC)
{
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(100,100);
pDC->SetViewportExt(50,-50);
CRect rect;
GetClientRect(&rect);
int w=rect.Width();
int h=rect.Height();
pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);
CDC *pMemDC=new CDC;
pMemDC->CreateCompatibleDC(pDC);
CBitmap *pBmp=new CBitmap;
pBmp->CreateCompatibleBitmap(pDC,w,h);
pMemDC->SelectObject(pBmp);
pMemDC->SetMapMode(MM_ANISOTROPIC);
pMemDC->SetWindowExt(100,100);
pMemDC->SetViewportExt(50,-50);
pMemDC->SetViewportOrg(w/2,h/2);
pMemDC->SelectObject(GetStockObject(WHITE_BRUSH));
pMemDC->Rectangle(-w,h,w,-h);
pMemDC->MoveTo(-w,0);
pMemDC->LineTo(w,0);
pMemDC->MoveTo(0,h);
pMemDC->LineTo(0,-h);
for(i=0;i<100;i+=3)
pMemDC->Rectangle(i,i,100+i,100+i);
pDC->BitBlt(-w,h,2*w,2*h,pMemDC,-w,h,SRCCOPY);}
把CMyView的逻辑坐标原点设置到窗口客户区的中点,x轴朝右,y轴朝上
并且让逻辑坐标系和设备坐标系的比例为2:1
然后画个坐标轴
接着再画一些矩形
因为这样会有闪烁,我就先把它画到内存,然后贴回来
但是不知道为什么总有问题
帮我看看代码有什么问题吧
代码如下:
void CMyView::OnDraw(CDC* pDC)
{
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(100,100);
pDC->SetViewportExt(50,-50);
CRect rect;
GetClientRect(&rect);
int w=rect.Width();
int h=rect.Height();
pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);
CDC *pMemDC=new CDC;
pMemDC->CreateCompatibleDC(pDC);
CBitmap *pBmp=new CBitmap;
pBmp->CreateCompatibleBitmap(pDC,w,h);
pMemDC->SelectObject(pBmp);
pMemDC->SetMapMode(MM_ANISOTROPIC);
pMemDC->SetWindowExt(100,100);
pMemDC->SetViewportExt(50,-50);
pMemDC->SetViewportOrg(w/2,h/2);
pMemDC->SelectObject(GetStockObject(WHITE_BRUSH));
pMemDC->Rectangle(-w,h,w,-h);
pMemDC->MoveTo(-w,0);
pMemDC->LineTo(w,0);
pMemDC->MoveTo(0,h);
pMemDC->LineTo(0,-h);
for(i=0;i<100;i+=3)
pMemDC->Rectangle(i,i,100+i,100+i);
pDC->BitBlt(-w,h,2*w,2*h,pMemDC,-w,h,SRCCOPY);}
(-w,-h)不就成了左下角了么
这个地方的参数应该是左上角的坐标啊
但是你看MSDN里面BITBLT的说明BOOL BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop );
xSrcSpecifies the logical x-coordinate of the upper-left corner of the source bitmap
只是说是源位图左上角的逻辑坐标
我这里x朝右,y朝上
那么(-w,-h)不成了左下角坐标么
这里和OnPrepareDC没关系吧
只是说是源位图左上角的逻辑坐标
========
这里的逻辑是什么呢?不是原来的默认逻辑了,而是x朝右,y朝上,你已经修改逻辑了
我现在的逻辑坐标系x朝右,y朝上
原点在窗口客户区中点
那么左上角,也就是点A的逻辑坐标不正是(-w,+h)么 _____________|_______________
|A | |
| | |
| | |
____|_____________|_______________|_____
| | |
| | |
| | |
|_____________|_______________|
|
|