C++中的DrawLine函数该怎么使用

ny1986 2012-08-15 02:14:58
想画一条直线,找了很多地方,讲的都是鼠标画线。我想指定两点画线,不用鼠标捕获。DrawLine()函数应该可以做到。但这个怎么使用呢?建立一个基本的MFC框架后,要进行怎样的设置才可以成功使用这个函数,请各位高手们给详细解释一下,最好能给一个例程,不胜感激。
另外,我看到很多计算机图形学的书上讲到各种画线算法,我狠困惑。使用MoveTo(),LineTo(), 或者DrawLine()不是可以直接画出来吗?干嘛还需要这样那样的画线算法呢?
...全文
2700 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ny1986 2012-08-17
  • 打赏
  • 举报
回复
谢谢大家的答复,但暂时还不是很懂,主要是不知道这样用到底根据什么,规则是在哪里规定的,可能还得好好看关于MFC的书吧!暂时结贴,分数送上。
傻X 2012-08-15
  • 打赏
  • 举报
回复
你可以在OnDraw和OnPaint函数中获得页面的
CDC指针,一般都叫pDC。
CPoint p1,p2;
pDC->MoveTo(p1);
pDC->LineTo(p2);
looklzg1108 2012-08-15
  • 打赏
  • 举报
回复
刚才写错了

C/C++ code
void DrawLinx(POINT p1,POINT p2)
{
MoveTo(p1);
LineTo(p2);
};
looklzg1108 2012-08-15
  • 打赏
  • 举报
回复
1楼说的很多,DrawLine是GDI+函数。自己可简单实现

void DrawLinx(POINT p1,POINT p2)
{
MoveTo(p1);
MoveTo(p2);
};
Gloveing 2012-08-15
  • 打赏
  • 举报
回复
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.
ywlfield 2012-08-15
  • 打赏
  • 举报
回复
MoveTo(),LineTo()是gdi的函数,DrawLine()是gdi+的函数,需要配置gdi+的环境才可以使用,
你可以参考这个配置http://read.newbooks.com.cn/info/50446.html. 如果vs08的话就不用导入库了

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧