写了个画bezier曲线程序,可就是画不出来,请各位xdjm帮帮忙,急啊
源代码如下
Private Declare Function PolyBezier Lib "gdi32" (ByVal hdc As Long, lppt As pointapi, ByVal cPoints As Long) As Long
Private Type pointapi
     X As Long
     Y As Long
 End Type
 Dim apt(0 To 3) As pointapi
Dim idx As Integer
Private Sub Form_Load()
scalmode = 3
idx = 0
End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If idx = 0 Then Cls
apt(idx).X = X: apt(idx).Y = Y
Circle (X, Y), 30, RGB(0, 0, 255)
If idx = 3 Then
PolyBezier Me.hdc, apt(0), 4
idx = 0
Else: idx = idx + 1
End If
End Sub

解决方案 »

  1.   

    Option ExplicitPrivate Type POINTAPI
        x As Long
        y As Long
    End TypePrivate Declare Function PolyBezier Lib "gdi32" _
                    (ByVal hdc As Long, _
                     lppt As POINTAPI, _
                     ByVal cpoints As Long) As LongDim Points(0 To 3) As POINTAPI
    Dim oldPoint As POINTAPI
    Dim Index As IntegerPrivate Sub command1_click()
        Unload Me
    End SubPrivate Sub form_load()
        Caption = "绘制贝塞尔曲线"
        Command1.Caption = "退出"
        ScaleMode = 3
    End SubPrivate Sub form_mousedown(button As Integer, _
        shift As Integer, x As Single, y As Single)
        Points(Index).x = x: Points(Index).y = y
        If Index = 0 Then
            Cls
        Else
            Line (oldPoint.x, oldPoint.y)-(x, y) '绘制特征多边形
        End If
        oldPoint.x = x: oldPoint.y = y
        Circle (x, y), 3, vbBlue
        If Index = 3 Then
            Form1.ForeColor = vbRed
            PolyBezier Me.hdc, Points(0), 4     '绘制贝赛尔曲线
            Index = 0
        Else
            Index = Index + 1
        End If
    End Sub
      

  2.   

    为什么不直接用GDI中的贝塞尔图线绘制函数?
      

  3.   

    '看一下你自己的程序的第二行,scalmode是什么,显然是scalemode,你的少了一个“e”:
    Private Sub Form_Load()
    scalmode = 3
    idx = 0
    End Sub'所以好的编程习惯中有一条就是在所有模块首加一句“option explicit”……
      

  4.   

    哈哈,谢谢laviewpbt,我刚才把我的程序和你的比较了一下,加上Option Explicit后才发现有个拼写错误,把scalemode拼成scalmode,看来强制变量声明还是很重要的。
       也感谢sworddx的参与,不过对于你的直接用gdi中的贝塞尔图线绘制函数绘图,我现在还不会用,不过我会找一些讲gdi得书刊看的,谢谢!
      

  5.   

    哎呀,刚看到xinliangyu的回帖,我也刚发现这个问题,谢谢啦^_^