想画一条直线,找了很多地方,讲的都是鼠标画线。我想指定两点画线,不用鼠标捕获。DrawLine()函数应该可以做到。但这个怎么使用呢?建立一个基本的MFC框架后,要进行怎样的设置才可以成功使用这个函数,请各位高手们给详细解释一下,最好能给一个例程,不胜感激。
另外,我看到很多计算机图形学的书上讲到各种画线算法,我狠困惑。使用MoveTo(),LineTo(), 或者DrawLine()不是可以直接画出来吗?干嘛还需要这样那样的画线算法呢?
另外,我看到很多计算机图形学的书上讲到各种画线算法,我狠困惑。使用MoveTo(),LineTo(), 或者DrawLine()不是可以直接画出来吗?干嘛还需要这样那样的画线算法呢?
你可以参考这个配置http://read.newbooks.com.cn/info/50446.html. 如果vs08的话就不用导入库了
==================
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.
{
MoveTo(p1);
MoveTo(p2);
};
void DrawLinx(POINT p1,POINT p2)
{
MoveTo(p1);
LineTo(p2);
};
CDC指针,一般都叫pDC。
CPoint p1,p2;
pDC->MoveTo(p1);
pDC->LineTo(p2);