天看了孙鑫老师的视频 实现了在状态栏显示坐标的功能,但这个坐标是屏幕坐标系下的坐标
我在思考,CAD下坐标显示的功能是如何实现的呢,即用户自定义的坐标系的坐标是如何实现的呢
于是我编了代码
View类中实现
void CMy042103View::OnDraw(CDC* pDC)
{
CMy042103Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowOrg(-100,100);//左上角坐标为(-100,100);
pDC->SetWindowExt(200,-200);//x向右为正,y向上为正;经过以上设置,坐标原点在客户区中心;
pDC->SetViewportOrg(0,0);//视口原点在客户区左上角;
CRect rect;
pDC->GetClientRect(&rect);
pDC->SetViewportExt(rect.Width,rect.Height);//把视口映射到整个客户区;
}
void CMy042103View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CFrameWnd*)GetParent())->SetMessageText(str);//在状态栏显示str;
CView::OnMouseMove(nFlags, point);
}
可是运行之后状态栏显示的依然是屏幕坐标,即左上角的坐标为0,0
请大侠指点一下啊
来源: http://www.programbbs.com/bbs/Announce.asp?boardID=20&posttype=1&score=cust&custscore=30
我在思考,CAD下坐标显示的功能是如何实现的呢,即用户自定义的坐标系的坐标是如何实现的呢
于是我编了代码
View类中实现
void CMy042103View::OnDraw(CDC* pDC)
{
CMy042103Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowOrg(-100,100);//左上角坐标为(-100,100);
pDC->SetWindowExt(200,-200);//x向右为正,y向上为正;经过以上设置,坐标原点在客户区中心;
pDC->SetViewportOrg(0,0);//视口原点在客户区左上角;
CRect rect;
pDC->GetClientRect(&rect);
pDC->SetViewportExt(rect.Width,rect.Height);//把视口映射到整个客户区;
}
void CMy042103View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CFrameWnd*)GetParent())->SetMessageText(str);//在状态栏显示str;
CView::OnMouseMove(nFlags, point);
}
可是运行之后状态栏显示的依然是屏幕坐标,即左上角的坐标为0,0
请大侠指点一下啊
来源: http://www.programbbs.com/bbs/Announce.asp?boardID=20&posttype=1&score=cust&custscore=30