可以画点并拖动点,画点与点之间的直线并可以鼠标拖动直线变形。用于画平面图(图:指数据结构中的图结构)。

解决方案 »

  1.   

    CoralDraw中的那种画法?贝尔曲线什么的,听说这种画法产生的年代并不遥远,具体实现方法还真不知道。
      

  2.   

    详解贝塞尔曲线http://zh.wikipedia.org/wiki/%E8%B2%9D%E8%8C%B2%E6%9B%B2%E7%B7%9Ahttp://www.jcwcn.com/article-32008-1.html
      

  3.   

    数据结构时增加一个变量:
    BOOL IsPress;//为真时是按下,为假时松下
    在鼠标左键按下时设真,在鼠标左键松开时设为假,这样,在鼠标移动函数里就根据IsPress的值来决定是否画线,是否移动
      

  4.   

    “ 还有,怎么确定鼠标指向了直线区域以及点附近的区域呢?如何得到直线的区域呢”
    这是一个 直线点击 测试的 问题。
    vc6 帮助中 有 一个 “W32HIT”的例子。
      

  5.   

    打开vc ,点 help 点 search ,输入 WIN32HIT 。
    点 显示主题。
    在 前面 有 例子 下载 链接。
      

  6.   

     哦哦,不过我的那个vc++ 似乎有点问题 没安装msdn..
      

  7.   

    确定鼠标坐标点的区域,用CRect类里的PtInRect函数(好象是这这写的,你查一下这个类里的函数就知道了)
      

  8.   


    画了点和直线 ,但是直线怎么用鼠标拖动变成曲线呢??类似windows画图中,原来是直线,用鼠标拖成曲线
      

  9.   

    下面的函数可以 把 3点 变为 2次Bezier曲线
    //
    BOOL  CTtfShowDlg::QuadraticBezier(CDC *pDC,const POINT* lpPoints, int nCount)
    {
    double  t;
    double  dt=(double)1/POINTS_ON_CURVE;
    CPoint  pt;
    int     i;
    //afxDump << nCount << "=nCount\n";
    for(i=0 ; i < nCount - 2 ; i += 2)
    {
    if(i==0)
    {// only 1 start point need to be set !
    pDC->MoveTo(lpPoints[0]);
    }
    for(t=0.0 ;t < 1.0 + dt ;t += dt)
    {// 3 points each,cubic Bezier curve.
    pt.x=(long)((1-t)*(1-t)*lpPoints[0+i].x +
            2*t*(1-t)*lpPoints[1+i].x +
    t*t*lpPoints[2+i].x );
    pt.y=(long)((1-t)*(1-t)*lpPoints[0+i].y +
            2*t*(1-t)*lpPoints[1+i].y +
    t*t*lpPoints[2+i].y );
    pDC->LineTo(pt);
    // pDC->SetPixel(pt,0xFF0000);// blue !
    }
    }
    //
    return TRUE;
    }
    把直线2端点 和 鼠标点击点 做成 CPoint pt[3];、、 鼠标点在 pt[1]
    调用:
    QuadraticBezier(pDC, pt, 3);
      

  10.   

    POINTS_ON_CURVE=40
    鼠标点 不 在曲线上 !
      

  11.   


    不好意思,好久没上CSDN了,我试一试哈
      

  12.   

    因为 QuadraticBezier 不通过 鼠标点 ,所以 不必测试鼠标在 直线上 ,你在 直线外 点击一下。
    (OnLButtonDown)把直线2端点 和 鼠标点击点 做成 CPoint pt[3];、、 鼠标点在 pt[1]

    至于“判断鼠标是否移动到了直线或曲线”还是 找 ‘W32HIT’ 例子。
      

  13.   

    Alternative to PtInRegion() for Hit-Testing
    Last reviewed: September 29, 1995
    Article ID: Q121960 
    //
    Win32: Hit Testing Lines and Curves
    Dennis Crain
    Microsoft Developer Network Technology GroupCreated: February 8, 1994Click to open or copy the files in the W32HIT sample application for this technical article.Abstract
    Useful graphics applications, such as CAD or drawing programs, permit the user to select and manipulate graphics objects. This article describes three methods for detecting if the user has selected a line or a curve.The first method is used to hit test lines. It uses two-dimensional vector techniques that resolve the vector components of the line and the point at which the user clicked the mouse. These vector methods are described in detail in the "Use of Two-Dimensional Vectors with Windows NT" technical article in the Microsoft® Development Library.
    ...
      

  14.   

    我把W32Hit上传了:
    “直线或曲线的点击测试.rar”0 分
    http://download.csdn.net/detail/schlafenhamster/4914656
    请参考。
      

  15.   

    使用函数
    BOOL PolyBezier(
      HDC hdc,            // handle to device context
      CONST POINT *lppt,  // pointer to endpoints and control points
      DWORD cPoints       // count of endpoints and control points
    );鼠标移动改变某个POINT的值,然后重画