请教VB高手一个polyline的问题
Dima(2001)AsSingleFori=0To2000Picture1.Line(i,a(i))-(i+1,a(i+1)),vbRedNext上述的一个画线程序,请...
Dim a(2001) As Single
For i = 0 To 2000
Picture1.Line (i, a(i))-(i + 1, a(i + 1)), vbRed
Next
上述的一个画线程序,请高手用polyline这个api写一下,我不会用这个API,谢谢啊. 展开
For i = 0 To 2000
Picture1.Line (i, a(i))-(i + 1, a(i + 1)), vbRed
Next
上述的一个画线程序,请高手用polyline这个api写一下,我不会用这个API,谢谢啊. 展开
2个回答
展开全部
首先是声名
Declare Function Polyline Lib "gdi32" Alias "Polyline" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
这里要用到hdc可以用getdc获得,hdc用完后用releasedc释放资源。所以这里还要声名这两个api
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
这里用到一个自定义类型POINTAPI,同样需要声明
type POINTAPI
x as long
y as long
end type
然后就可以调用了。
比如你直接在屏幕上作画,那就这样
dim hdc as long ‘保存句柄用
dim points(3) as POINTAPI ’假设画三角
‘型, 三个点存在这个数组里
points(0).x=0
points(0).y=0
points(1).x=100
points(1).y=0
points(2).x=0
points(2).y=100
hdc=getdc(0)'获得句柄
Polyline hdc,points(0),3 '画三角形
'第一个参数表示句柄,第二个参数表示点的数组,第三个参数代表点的个数。
releasedc 0,hdc ’释放句柄
这样就可以了。
Declare Function Polyline Lib "gdi32" Alias "Polyline" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
这里要用到hdc可以用getdc获得,hdc用完后用releasedc释放资源。所以这里还要声名这两个api
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
这里用到一个自定义类型POINTAPI,同样需要声明
type POINTAPI
x as long
y as long
end type
然后就可以调用了。
比如你直接在屏幕上作画,那就这样
dim hdc as long ‘保存句柄用
dim points(3) as POINTAPI ’假设画三角
‘型, 三个点存在这个数组里
points(0).x=0
points(0).y=0
points(1).x=100
points(1).y=0
points(2).x=0
points(2).y=100
hdc=getdc(0)'获得句柄
Polyline hdc,points(0),3 '画三角形
'第一个参数表示句柄,第二个参数表示点的数组,第三个参数代表点的个数。
releasedc 0,hdc ’释放句柄
这样就可以了。
展开全部
Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Dim p(5) As POINTAPI
p(0).x = 20
p(0).y = 20
p(1).x = 180
p(1).y = 50
p(2).x = 90
p(2).y = 170
Polyline Picture1.hdc, p(0), 3
End Sub
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Dim p(5) As POINTAPI
p(0).x = 20
p(0).y = 20
p(1).x = 180
p(1).y = 50
p(2).x = 90
p(2).y = 170
Polyline Picture1.hdc, p(0), 3
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询