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)点的坐标呢?)

解决方案 »

  1.   

    CDC::DPtoLP()见: http://msdn2.microsoft.com/zh-cn/library/kc2xe1x4(vs.80).aspx
      

  2.   

    没太懂哦,请细细指教一下其实我的主要目的是:在void CElevationView::OnLButtonDown(UINT nFlags, CPoint point)中判断鼠标按下的位置是否在
    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);……
    }
    画出的坐标系的某个区域中
      

  3.   

    用CRect把你画的坐标系的范围定义下来, 然后用CRect::PtInRect()判断一个点是否在这个CRect范围内就可以了.那个点的坐标也必须是当前Mapping Mode下的, 不能是MM_TEXT下的, 因为你已经SetMapMode了
      

  4.   

    我是这样做的:
    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下的值
    该怎样统一呢?
      

  5.   

    所以用上面的CDC::DPtoLP来转换.
      

  6.   

    CDC::DPtoLP中的参数应该为什么呢?CDC::DPtoLP应该放在哪个位置?
    谢谢
      

  7.   

    CDC::DPtoLP  
    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.