首页 > 代码库 > VB API 之 第十课 图像编程(三)

VB API 之 第十课 图像编程(三)

  首先绘制多边形的API函数有:

  Polygon();   //描绘一个多边形,由两点或三点的任意系列构成

  polyPolygon();   //用当前选定的画笔绘画两个或多个多边形

  PolyPolyline();   //用当前选定的画笔描绘两个或多个多边形

  首先来看Polygon的函数原型

Private Declare Function Polygon Lib "gdi32" Alias "Polygon" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long

  参数说明

  hdc: Long  // 绘制多边形设备的句柄

  lpPoint  //指向一个POINTAPI类型的数组

  nCount:Long  //多边形的顶点数

  返回Long类型值,返回0表示失败,不为0则表示成功

Option ExplicitPrivate Type POINTAPI    x As Long    y As LongEnd TypePrivate Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As LongDim Pos(5) As POINTAPIDim Flag As BooleanDim i As Integer绘图标志变量
Private Sub Command1_Click()Flag = True开始绘图End Sub
Private Sub Command2_Click()Flag
= False结束绘图End Sub
Private Sub Form_Load()Flag
= False禁止绘图Me.ScaleMode = 3Me.Picture1.ScaleMode = 3设置对象坐标的度量单位为像素i = 0End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)If Flag ThenPos(i).x
= xPos(i).y = yIf (i >= 3) ThenPolygon Me.Picture1.hdc, Pos(0), 4将多边形的边数设置为4‘你也可以自己修改多边形的边数Me.Picture1.Circle (x, y), 3i = 0Exit SubEnd IfEnd If绘制多边形If (i <= 3) Theni = i + 1Me.Picture1.Circle (x, y), 3End IfEnd Sub

 

VB API 之 第十课 图像编程(三)