求教:怎样调用绘制数学曲线的API函数
在API中,绘制数学曲线的函数:Public Declare Function GdipDrawCurve2 Lib "gdiplus" (ByVal Graphics As Long, ByVal pen As Long, Points As POINTF, ByVal count As Long, ByVal tension As Single) As GpStatus
调用时,Points怎样得到?
敬请高手指点。
谢谢。 --------------------编程问答-------------------- 参考:http://msdn.microsoft.com/en-us/library/ms536144(v=vs.85).aspx --------------------编程问答-------------------- 这是GDI+的函数,首先你的创建设备场景、画笔
看看这个 --------------------编程问答-------------------- 承蒙两位及时指教,十分感激。
遵嘱,都看了。但没有找到答案。
过去用过绘制弧线的API,相对简单,参数中没有Points和pen参数。现在的难题是不知道怎样设置参数,来调用绘制数学曲线的API函数。
敬请明示。
谢谢。 --------------------编程问答--------------------
'Points参数是个类型POINTF:--------------------编程问答-------------------- '定义FIXED类型
Private Type POINTFX
x As FIXED
y As FIXED
End Type
private pp as POINTF
'用PP来设置座标值:
debug.print pp.x,pp.y
Private Type FIXED
fract As Integer
Value As Integer
End Type
'定义POINTFX类型
Private Type POINTFX
x As FIXED
y As FIXED
End Type
private pp as POINTFX
'用PP来设置座标值:
debug.print pp.x.fract ,pp.y.fract
--------------------编程问答-------------------- 高手拔冗指教,幸甚。
从上午试验到现在,还是不得要领。实在是我太笨。
两个问题挡道。
(1)参数中的points不能作为参数类型,试运行时提示错误。
(2)暂时删除这一参数,软件可运行。因为曲线至少需要三个点,所以定义一个数组dians(1 to 4),是pointf数据类型。但调用绘制曲线的API函数,提示编译错误:ByRef参数类型不符。
呈上源码:
Private Sub Command23_Click() '临时调试按钮
Dim wdians(1 To 4) As POINTF
Dim wdianshu As Long
Dim wzhangli As Single
Dim huabi As Long
wdians(1).X = 100: wdians(1).Y = 100: wdians(2).X = 200: wdians(1).Y = 150: wdians(3).X = 400: wdians(3).Y = 50
wdianshu = 3: wzhangli = 1
GdipDrawCurve2 Picture1.hdc, huabi, (wdians()), wdianshu, wzhangli
End Sub
耽误您的宝贵时间,真很抱歉。
谢谢。 --------------------编程问答-------------------- POINTF类型中还有一个类型FIXED,忘了吗?
要这样用:wdians(1).X.Value = 100 --------------------编程问答-------------------- 你的用法不正确啊 --------------------编程问答-------------------- 推荐使用tlb的,稳定 --------------------编程问答--------------------
--------------------编程问答-------------------- 试了又试,还是不得要领。怀疑是VB6.0的版本问题,下载,安装了中文企业版。运行时,编译通不过。惭愧。
'使用Gdiplus.tlb,将其放到system32中,然后添加对其的引用
'手动设置Form的AutoRedraw=True,ScaleMode=Pixels
Option Explicit
Dim lngGraphics As Long
Dim gpP As GpStatus
Dim lngPen1 As Long
Dim lngToken As Long
Dim GpInput As GdiplusStartupInput
Dim p As POINTF
Private Sub Command1_Click()
gpP = GdipCreateFromHDC(Me.hDC, lngGraphics)
gpP = GdipCreatePen1(&H80FF0000, 2, UnitPixel, lngPen1)
p.X = 100
p.Y = 100
gpP = GdipDrawCurve2(lngGraphics, lngPen1, p, 10, 5)
Me.Refresh
End Sub
Private Sub Form_Load()
Dim bolP As Boolean
With Me
.Caption = "GDIPlus范例"
.Width = 960 * 15
.Height = 720 * 15
.Left = (Screen.Width - .Width) * 0.5
.Top = (Screen.Height - .Height) * 0.5
End With
GpInput.GdiplusVersion = 1
If lngToken = 0 Then bolP = (GdiplusStartup(lngToken, GpInput) = Ok)
End Sub
按东方所教格式,定义Type,提示是“无效内部过程”。定义pp,报错:“子程序和函数中的属性无效”。
至于tlb,实在是啃不动。
绘制数学曲线的API函数:
Private Declare Function GdipDrawCurve2 Lib "gdiplus" (ByVal Graphics As Long, ByVal pen As Long, Points As POINTF, ByVal count As Long, ByVal tension As Single) As Long
如何调用?
谢谢。 --------------------编程问答--------------------
其实很简单,只需要你下载Gdiplus.tlb放到Systen32目录下,然后再在工程中对其引用就可以了。
--------------------编程问答-------------------- 高手如此认真,深以为感。
'使用Gdiplus.tlb,将其放到system32中,然后添加对其的引用
'手动设置Form的AutoRedraw=True,ScaleMode=Pixels
Option Explicit
Dim lngGraphics As Long
Dim gpP As GpStatus
Dim lngPen1 As Long
Dim lngToken As Long
Dim GpInput As GdiplusStartupInput
Dim p(0 To 99) As POINTF
Private Sub Command1_Click()
Dim intP As Integer
Me.Cls
gpP = GdipCreateFromHDC(Me.hDC, lngGraphics)
gpP = GdipCreatePen1(&H80808080, 2, UnitPixel, lngPen1)
For intP = 0 To 99
p(intP).X = intP * 10
p(intP).Y = 200 + 50 * Sin((intP * 10) / 100 * 2 * 3.1415926)
Next intP
gpP = GdipDrawCurve2(lngGraphics, lngPen1, p(0), 100, 10)
Me.Refresh
End Sub
Private Sub Form_Load()
Dim bolP As Boolean
With Me
.Caption = "GDIPlus范例"
.Width = 960 * 15
.Height = 720 * 15
.Left = (Screen.Width - .Width) * 0.5
.Top = (Screen.Height - .Height) * 0.5
End With
GpInput.GdiplusVersion = 1
If lngToken = 0 Then bolP = (GdiplusStartup(lngToken, GpInput) = Ok)
End Sub
横下一条心,下功夫啃一星期。有老师,没有过不去的火焰山。
谢谢。 --------------------编程问答--------------------
补充:VB , API