ExtFloodFill VB声明 
Declare Function ExtFloodFill Lib "gdi32" Alias "ExtFloodFill" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long 
说明 
在指定的设备场景里,用当前选择的刷子填充一个区域 
返回值 
Long,非零表示成功,零表示失败。会设置GetLastError 
参数表 
参数 类型及说明 
hdc Long,设备场景的句柄 
x,y Long,开始填充的一个点,采用逻辑坐标表示 
crColor Long,要使用的边界颜色 
wFillType Long,欲执行的填充类型,由下述任何一个常数决定 
FLOODFILLBORDER 等同于FloodFill函数的功能 
FLOODFILLSURFACE 从指定的点向外填充,只到找到了crColor颜色(在边框采用了多种颜色时使用) 
注解 
如指定了FLOODFILLBORDER,那么x,y点绝对不能为crColor颜色。如指定了FLOODFILLSURFACE,那么x,y点必须是crColor颜色。这个函数只能在光栅设备中使用。可用GetDeviceCaps函数判断设备是否支持这个函数
 
提示 
一旦指定了FLOODFILLBORDER,务必保证初始点的颜色没有crColor。如果使用的是FLOODFILLSURFACE,务必保证初始点有颜色crColor(这是函数执行失败最常见的两个原因)。注意保证初始点位于剪切区内 

解决方案 »

  1.   

    'FloodFill
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long
    Const FLOODFILLBORDER = 0 ' Fill until crColor& color encountered.
    Const FLOODFILLSURFACE = 1 ' Fill surface until crColor& color not encountered.
    Const crNewColor = &HFFFF80
    Dim mBrush As Long
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Create a solid brush
        mBrush = CreateSolidBrush(crNewColor)
        'Select the brush into the PictureBox' device context
        SelectObject Picture1.hdc, mBrush
        'API uses pixels
        Picture1.ScaleMode = vbPixels
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'Delete our new brush
        DeleteObject mBrush
    End Sub
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        'Floodfill...
        ExtFloodFill Picture1.hdc, x, y, GetPixel(Picture1.hdc, x, y), FLOODFILLSURFACE
    End Sub