Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 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
'Description:
' The ExtFloodFill function fill an area using the color of the current selected brush in the target device context.
'
'Params:
' hdc: Handle the device context in wich the function will be used.
'
' X: The x-position where the filling will start.
'
' Y: The y-position where the filling will start.
'
' crColor: The color value of the boundary or the area to be filled, depending of the wFillType flag.
'
' wFillType: The type of the fill operation to perform. Can be:
Private Const FLOODFILLBORDER = 0
'The area to be filled is bounded with crColor, the filling will be done in all directions _
'Until crColor is reached.
Private Const FLOODFILLSURFACE = 1
'The area to be filled is defined by crColor, the filling will be done in all directions _
'as long as crColor is encountered.
Private Sub Form_Load()
Dim BackColor As Long
Dim hPrevBrush As Long
Dim hNewBrush As Long
'--> this just draw a rectangle to the screen to have a shape to fill.
'The long color for the new brush
BackColor = RGB(13, 168, 252)
'Create a brush
hNewBrush = CreateSolidBrush(BackColor)
'Select the new brush in the dc.
hPrevBrush = SelectObject(Me.hdc, hNewBrush)
'Draw a rectangle
Rectangle Me.hdc, 10, 10, 300, 150
'Put back the previous brush in the dc.
SelectObject Me.hdc, hPrevBrush
'Delete the new brush
DeleteObject hNewBrush
End Sub
Public Function ColorFill(hdc As Long, x As Long, y As Long, ColorToFill As Long, FillWithColor As Long)
'--> this function will fill an area of ColorToFill with FillWithColor
Dim hTempBrush As Long
Dim hPrevBrush As Long
'Create the brush that will be used to fill the area.
hTempBrush = CreateSolidBrush(FillWithColor)
'Select the brush into the dc.
hPrevBrush = SelectObject(hdc, hTempBrush)
'Fill the area.
ExtFloodFill hdc, x, y, ColorToFill, FLOODFILLSURFACE
'Set back the previous brush
SelectObject hdc, hPrevBrush
'Delete the temp brush.
DeleteObject hTempBrush
End Function
Private Sub Form_Click()
ColorFill Me.hdc, 20, 20, RGB(13, 168, 252), RGB(123, 234, 176)
Form1.Refresh
End Sub