PDA

Click to See Complete Forum and Search --> : Color Fill


davecooper
Sep 16th, 2000, 08:15 PM
I recall from the distant past that there is an API function that fills a closed region. I'm having trouble finding it.

Thanks

Sep 16th, 2000, 09:20 PM
This what your looking for?

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As _
Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As _
RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long

' Shade a form
'
' Optional Arguments:
' StartColor is what color to start with.
' (Default = vbBlue)
' Fstep is the number of steps to use to fill the form.
' (Default = 64)
' Cstep is the color step (change in color per step).
' (Default = 4)
'
' Note: the effect can be reversed by calling ShadeForm with
' a StartColor near black (but not completely 0) and by
' setting a negative color step.
'
Public Sub ShadeForm(f As Form, Optional StartColor As Variant, Optional Fstep As Variant, Optional Cstep As Variant)
Dim FillStep As Single ' Not an integer because sometimes
' rounding leaves a large bottom region
Dim c As Long
Dim FillArea As RECT
Dim i As Integer
Dim oldm As Integer
Dim hBrush As Long
Dim c2(1 To 3) As Long
Dim cs2(1 To 3) As Long
Dim fs As Long
Dim cs As Integer

' Set defaults
fs = IIf(IsMissing(Fstep), 64, CLng(Fstep))
cs = IIf(IsMissing(Cstep), 4, CInt(Cstep))
c = IIf(IsMissing(StartColor), vbBlue, CLng(StartColor))


oldm = f.ScaleMode
f.ScaleMode = vbPixels
FillStep = f.ScaleHeight / fs
FillArea.Left = 0
FillArea.Right = f.ScaleWidth
FillArea.Top = 0

' Break down the color and set individual
' color steps
c2(1) = c And 255#
cs2(1) = IIf(c2(1) > 0, cs, 0)
c2(2) = (c \ 256#) And 255#
cs2(2) = IIf(c2(2) > 0, cs, 0)
c2(3) = (c \ 65536#) And 255#
cs2(3) = IIf(c2(3) > 0, cs, 0)


For i = 1 To fs
FillArea.Bottom = FillStep * i

hBrush = CreateSolidBrush(RGB(c2(1), c2(2), c2(3)))
FillRect f.hdc, FillArea, hBrush
DeleteObject hBrush

' Could do this in a loop, but it's simple
' and may be faster.
c2(1) = (c2(1) - cs2(1)) And 255#
c2(2) = (c2(2) - cs2(2)) And 255#
c2(3) = (c2(3) - cs2(3)) And 255#

FillArea.Top = FillArea.Bottom
Next i

f.ScaleMode = oldm
End Sub

Sep 17th, 2000, 02:31 PM
if you want to fill a polygon or something similar, try to use this:
Declare Function ExtFloodFill Lib "gdi32.dll" (ByVal hdc As Long, ByVal nXStart As Long, ByVal nYStart As Long, ByVal crColor As Long, ByVal fuFillType As Long) As Long

I found it on a site. It's easy to handle. you can find a lot of informations about it at this page: http://www.vbapi.com/ref/e/extfloodfill.html

Good-bye (i hope that you have found what you were looking for)

davecooper
Sep 17th, 2000, 02:46 PM
Many thanks!

Zvonko
Sep 17th, 2000, 03:25 PM
I saw something similar on www.vbfrood.de. It was about creating those setup screens, just more complex (you could specify more colors, you could make it in triangle...). Look there, you'll find it.