【函数】
FillRgn【操作系统】
Win9X:Yes
WinNT:Yes【声明】
FillRgn Lib "gdi32" Alias "FillRgn" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long【说明】 用指定刷子填充指定区域 【返回值】 Long,执行成功为非零值,失败则为0 【其它】
【参数表】
hdc ------------ Long,设备场景句柄 hRgn ----------- Long,以数据设备坐标填充的区域句柄 hBrush --------- Long,要用的刷子的句柄
FillRgn【操作系统】
Win9X:Yes
WinNT:Yes【声明】
FillRgn Lib "gdi32" Alias "FillRgn" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long【说明】 用指定刷子填充指定区域 【返回值】 Long,执行成功为非零值,失败则为0 【其它】
【参数表】
hdc ------------ Long,设备场景句柄 hRgn ----------- Long,以数据设备坐标填充的区域句柄 hBrush --------- Long,要用的刷子的句柄
x As Long
y As Long
End Type
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Const ALTERNATE = 1 ' ALTERNATE and WINDING are
Const WINDING = 2 ' constants for FillMode.
Const BLACKBRUSH = 4 ' Constant for brush type.
Private Sub Form_Paint()
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
Me.Cls
' Number of vertices in polygon.
NumCoords = 3
' Set scalemode to pixels to set up points of triangle.
Me.ScaleMode = vbPixels
' Assign values to points.
poly(1).x = Form1.ScaleWidth / 2
poly(1).y = Form1.ScaleHeight / 2
poly(2).x = Form1.ScaleWidth / 4
poly(2).y = 3 * Form1.ScaleHeight / 4
poly(3).x = 3 * Form1.ScaleWidth / 4
poly(3).y = 3 * Form1.ScaleHeight / 4
' Polygon function creates unfilled polygon on screen.
' Re FillRgn statement to see results.
Polygon Me.hdc, poly(1), NumCoords
' Gets stock black brush.
hBrush = GetStockObject(BLACKBRUSH)
' Creates region to fill with color.
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
' If the creation of the region was successful then color.
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
DeleteObject hRgn
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Declare Function Polygon Lib "gdi32" Alias "Polygon" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
说明
描绘一个多边形,由两点或三点的任意系列构成。windows会将最后一个点与第一个点连接起来,从而封闭多边形。多边形的边框用当前选定的画笔描绘,多边形用当前选定的刷子填充
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hdc Long,用于描绘的设备场景
lpPoint POINTAPI,在nCount POINTAPI结构数组中的第一个POINTAPI结构
nCount Long,多边形的总点数(顶点数)
注解
GetPolyFillMode 和 SetPolyFillMode 函数决定了如何在多边形内部填充
'Polygon Fillmode
Private Const ALTERNATE = 1
Private Const WINDING = 2
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetPolyFillMode Lib "gdi32" (ByVal hdc As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function GetPolyFillMode Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Sub Form_Paint()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim PentaPoints(1 To 5) As POINTAPI, Cnt As Long
Const PentagramWidth As Long = 150
'initialize the points
PentaPoints(1).x = PentagramWidth / 2
PentaPoints(1).y = 0
PentaPoints(2).x = (PentagramWidth / 4) * 3
PentaPoints(2).y = PentagramWidth
PentaPoints(3).x = 0
PentaPoints(3).y = PentagramWidth / 3
PentaPoints(4).x = PentagramWidth
PentaPoints(4).y = PentagramWidth / 3
PentaPoints(5).x = PentagramWidth / 4
PentaPoints(5).y = PentagramWidth
'set the form's fillmode to solid and fillcolor to red
Me.FillStyle = vbSolid
Me.FillColor = vbRed
'set the polygon fillmode to winding
If GetPolyFillMode(Me.hdc) <> WINDING Then SetPolyFillMode Me.hdc, WINDING
'draw the polygon
Polygon Me.hdc, PentaPoints(1), 5
'move the points to the right
For Cnt = 1 To 5
PentaPoints(Cnt).x = PentaPoints(Cnt).x + PentagramWidth + 20
Next Cnt
'set the polygon fillmode to alternate
SetPolyFillMode Me.hdc, ALTERNATE
'draw the second polygon
Polygon Me.hdc, PentaPoints(1), 5
End Sub