This little program demonstrates two basic graphics programming principles:

1) Simple “painting” code - basically, connecting a series of lines together as the user drags their mouse around.

2) An implementation of the built-in Windows API function “ExtFloodFill”, which can fill a contiguous region of an image. (Photoshop users may know this as the “paint bucket” tool.)

ExtFloodFill requires the following declaration (VB format):

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

To use the program, draw several lines using the left mouse button, then fill contiguous regions (with random colors) via the right button.

fill_screenshot

Download the sample app and source code from GitHub

For a much more powerful (and complicated) region-fill implementation, you might review the source code for the fill tool in PhotoDemon, my open-source photo editor.