
Fading Colors in a Window
Sure do, heres some code:
In General Declarations
' global variables for screen color settings
' the integer values should be set with true or false to get valid values
' any or all back colors could be set at one time
Global RedBack As Integer ' set to decide if you
want to add red use true or false
Global GreenBack As Integer ' set to decide if you want to add green
use true or false
Global BlueBack As Integer ' set to decide if you want to add blue use
true or false
Global blnHighColorMode As Boolean ' setting to false will turn off faded
backgrounds
Global FadeBlending As Double ' set as to how quickly you want the color
to fade to black
Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex
As Long) As Long
Declare Function GetDC Lib "User32" (ByVal hWnd As Long) As Long
Function GetMaxColors(frm As Form) As Long
Dim myhdc As Double
Dim NUMCOLORS As Double ' Number of colors the device supports
Dim SIZEPALETTE As Double ' Number of entries in physical
palette
Dim COLORRES As Double ' Actual color resolution
NUMCOLORS = 24
SIZEPALETTE = 104
COLORRES = 108
myhdc = GetDC(frm.hWnd)
GetMaxColors = GetDeviceCaps(myhdc, 24)
End Function
Sub FadeForm(frm As Form)
' Draws a fading background on a form
' Cannot be used to draw on a MDI Parent form
Dim SaveScale%, SaveStyle%, SaveRedraw%
Dim i&, j&, x&, Y&, pixels&
If GetMaxColors(frm) > 0 Then
Else
If blnHighColorMode = True Then
'Save current settings
SaveScale = frm.ScaleMode
SaveStyle = frm.DrawStyle
SaveRedraw = frm.AutoRedraw
' Paint Screen
frm.ScaleMode = 3
pixels = (frm.Height * FadeBlending) / Screen.TwipsPerPixelY
x = pixels / 64# + 0.5
frm.DrawStyle = 5
frm.AutoRedraw = True
For j = 0 To pixels Step x
Y = 240 - 245 * j \ pixels ' can tweak this to
preference actually causes color banding
If Y < 0 Then Y = 0 'just in case
frm.Line (-2, j - 2)-(Screen.Width + 2, j + x + 3),
RGB(-RedBack * Y, -GreenBack * Y, -BlueBack * Y), BF
Next j
' reset to previous settings
frm.ScaleMode = SaveScale
frm.DrawStyle = SaveStyle
frm.AutoRedraw = SaveRedraw
End If
End If
End Sub
Quote:
> How can I slowly fade all the Colors of a Window either to black or to
> white?
> Does anybody know?
> Thanks in advance!!