想画一条直线,找了很多地方,讲的都是鼠标画线。我想指定两点画线,不用鼠标捕获。DrawLine()函数应该可以做到。但这个怎么使用呢?建立一个基本的MFC框架后,要进行怎样的设置才可以成功使用这个函数,请各位高手们给详细解释一下,最好能给一个例程,不胜感激。
另外,我看到很多计算机图形学的书上讲到各种画线算法,我狠困惑。使用MoveTo(),LineTo(), 或者DrawLine()不是可以直接画出来吗?干嘛还需要这样那样的画线算法呢?

解决方案 »

  1.   

    MoveTo(),LineTo()是gdi的函数,DrawLine()是gdi+的函数,需要配置gdi+的环境才可以使用,
    你可以参考这个配置http://read.newbooks.com.cn/info/50446.html. 如果vs08的话就不用导入库了
      

  2.   

    MoveTo、LineTo,MFC中都可以用
    ==================
    Graphics::DrawLine(Pen* pen, Point& pt1, Point& pt2)
    The DrawLine method draws a line that connects two points.Status DrawLine(
      const Pen* pen,
      const Point& pt1,
      const Point& pt2
    );
    Parameters
    pen 
    [in] Pointer to a pen that is used to draw the line. 
    pt1 
    [in] Reference to a Point object that specifies the start of the line. 
    pt2 
    [in] Reference to a Point object that specifies the end of the line. 
    Return Values
    If the method succeeds, it returns Ok, which is an element of the Status enumeration.If the method fails, it returns one of the other elements of the Status enumeration.Example Code [C++]
    The following example draws a line.VOID Example_DrawLine(HDC hdc)
    {
       Graphics graphics(hdc);   // Create a Pen object.
       Pen blackPen(Color(255, 0, 0, 0), 3);   // Create two Point objects that define the line.
       Point point1(100, 100);
       Point point2(500, 100);   // Draw the line.
       graphics.DrawLine(&blackPen, point1, point2);
    }
    Requirements 
      Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
      Redistributable: Requires GDI+ on Windows NT 4.0 SP6; Windows 2000; and Windows 98/Me.
      Header: Declared in Gdiplusgraphics.h; include Gdiplus.h.
      

  3.   

    1楼说的很多,DrawLine是GDI+函数。自己可简单实现void DrawLinx(POINT p1,POINT p2)
    {
       MoveTo(p1);
       MoveTo(p2);
    };
      

  4.   

    刚才写错了C/C++ code
    void DrawLinx(POINT p1,POINT p2)
    {
       MoveTo(p1);
       LineTo(p2);
    };
      

  5.   

    你可以在OnDraw和OnPaint函数中获得页面的
    CDC指针,一般都叫pDC。
    CPoint p1,p2;
    pDC->MoveTo(p1);
    pDC->LineTo(p2);
      

  6.   

    谢谢大家的答复,但暂时还不是很懂,主要是不知道这样用到底根据什么,规则是在哪里规定的,可能还得好好看关于MFC的书吧!暂时结贴,分数送上。