CScrollView结构设定滚动页面大小及滚动位置:
void CElevationView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate(); CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100000; CSize sizePage(sizeTotal.cx/2, sizeTotal.cy/2);
CSize sizeLine(sizeTotal.cx/50, sizeTotal.cy/50); SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine); ScrollToPosition(CPoint(39*sizeTotal.cx/100, -40*sizeTotal.cy/100));
}设定映射关系,及新的坐标原点位置:
void CElevationView::OnDraw(CDC* pDC)
{
CElevationDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//坐标原点转移
pDC->SetMapMode(MM_HIMETRIC);
pDC->SetWindowOrg(-50000, 50000); //画坐标轴
CPen xPen(PS_SOLID, 50, RGB(255, 0, 0));
CPen yPen(PS_SOLID, 50, RGB(0, 255, 0));
pDC->SelectObject(&xPen);
pDC->MoveTo(0, 0);
pDC->LineTo(50000, 0);
pDC->SelectObject(&yPen);
pDC->MoveTo(0, 0);
pDC->LineTo(0, 50000);
pDC->SelectObject(pOldPen);……
}怎样实现void CElevationView::OnLButtonDown(UINT nFlags, CPoint point) 得到的point点坐标在新的坐标系内?(就是说,例如:点击坐标原点时,返回的是视口的相对像素坐标,怎样自动变换为MM_HIMETRIC坐标系下(0,0)点的坐标呢?)
void CElevationView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate(); CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100000; CSize sizePage(sizeTotal.cx/2, sizeTotal.cy/2);
CSize sizeLine(sizeTotal.cx/50, sizeTotal.cy/50); SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine); ScrollToPosition(CPoint(39*sizeTotal.cx/100, -40*sizeTotal.cy/100));
}设定映射关系,及新的坐标原点位置:
void CElevationView::OnDraw(CDC* pDC)
{
CElevationDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//坐标原点转移
pDC->SetMapMode(MM_HIMETRIC);
pDC->SetWindowOrg(-50000, 50000); //画坐标轴
CPen xPen(PS_SOLID, 50, RGB(255, 0, 0));
CPen yPen(PS_SOLID, 50, RGB(0, 255, 0));
pDC->SelectObject(&xPen);
pDC->MoveTo(0, 0);
pDC->LineTo(50000, 0);
pDC->SelectObject(&yPen);
pDC->MoveTo(0, 0);
pDC->LineTo(0, 50000);
pDC->SelectObject(pOldPen);……
}怎样实现void CElevationView::OnLButtonDown(UINT nFlags, CPoint point) 得到的point点坐标在新的坐标系内?(就是说,例如:点击坐标原点时,返回的是视口的相对像素坐标,怎样自动变换为MM_HIMETRIC坐标系下(0,0)点的坐标呢?)
void CElevationView::OnDraw(CDC* pDC)
{
CElevationDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//坐标原点转移
pDC->SetMapMode(MM_HIMETRIC);
pDC->SetWindowOrg(-50000, 50000); //画坐标轴
CPen xPen(PS_SOLID, 50, RGB(255, 0, 0));
CPen yPen(PS_SOLID, 50, RGB(0, 255, 0));
pDC->SelectObject(&xPen);
pDC->MoveTo(0, 0);
pDC->LineTo(50000, 0);
pDC->SelectObject(&yPen);
pDC->MoveTo(0, 0);
pDC->LineTo(0, 50000);
pDC->SelectObject(pOldPen);……
}
画出的坐标系的某个区域中
void CElevationView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC;
pDC=this->GetDC(); //保留原Pen
CPen* pOldPen;
CPen LinePen(PS_SOLID, 150, RGB(255, 0, 0)); //画矩形框
pOldPen=pDC->SelectObject(&LinePen); CRgn rect;
rect.CreateRectRgn(-1000, 750, 1000, -750); if (rect.PtInRegion(point))
{
pDC->MoveTo(PaneArray.GetAt(0).point_left_bottom);
pDC->LineTo(PaneArray.GetAt(0).point_right_bottom);
pDC->LineTo(PaneArray.GetAt(0).point_right_top);
pDC->LineTo(PaneArray.GetAt(0).point_left_top);
pDC->LineTo(PaneArray.GetAt(0).point_left_bottom);
} pDC->SelectObject(pOldPen);
CScrollView::OnLButtonDown(nFlags, point);
}关键是point是视口坐标系MM_TEXT下的值
而
CRgn rect;
rect.CreateRectRgn(-1000, 750, 1000, -750);
是pDC->SetWindowOrg(-50000, 50000);后MM_HIMETRIC下的值
该怎样统一呢?
谢谢
void DPtoLP( LPPOINT lpPoints, int nCount = 1 ) const;void DPtoLP( LPRECT lpRect ) const;void DPtoLP( LPSIZE lpSize ) const;ParameterslpPointsPoints to an array of POINT structures or CPoint objects.nCountThe number of points in the array.lpRectPoints to a RECT structure or CRect object. This parameter is used for the simple case of converting one rectangle from device points to logical points.lpSizePoints to a SIZE structure or CSize object.ResConverts device units into logical units. The function maps the coordinates of each point, or dimension of a size, from the device coordinate system into GDI’s logical coordinate system. The conversion depends on the current mapping mode and the settings of the origins and extents for the device’s window and viewport.