Lvjinjie

吕金杰 mobile:13662665247 E-mail:LVJINJIE@126.COM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

由于最近工作忙,多日未打理博客了,故今日有闲,发一个VB调用API涵数画正弦波的代码供大家参考.

代码如下:

Option Explicit
Dim Points() As POINTAPI
Dim NumPoints As Integer
Dim ZanTin1
Dim apik1
Dim apik2
Dim V
Const pi = 3.14159265358979
Private Type POINTAPI
        x As Long
        y As Long
    End Type
   Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Select Case Button
Case 1
ReDim Points(0 To 2)
V = 100
Picture1.Cls
ZanTin1 = True
apik1 = 0
Do While ZanTin1
apik1 = apik1 + 1
NumPoints = 2
apik2 = (Sin(pi / 180 * apik1)) * V
Points(1).x = apik1 - 1
Points(2).x = apik1
Points(1).y = 200 - apik2
Points(2).y = 200 - apik2
If Polyline(Picture1.hdc, Points(1), NumPoints) = 0 Then Exit Sub
If apik1 > 742 Then
ZanTin1 = False
End If
DoEvents
Loop
Case 2
End
End Select
End Sub

这只是一个例子,将此段代码稍微修改一下,也可画方波,阶梯波,三角波,和任意曲线,特别适用于对记录画线速度有要求的场合.如虚拟示波器.记录仪表等...

posted on 2010-05-06 07:25  金杰  阅读(1514)  评论(0编辑  收藏  举报