Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fade in Form

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
0
0
CA
Hey guys,

Is there a way to have a form fade in instead of just appear?

Thanks,

Jack
 
'*This module currently either
'*explodes or implodes a form.

'*The larger the "Movement" value the slower the
'*explosion or implosion. It is possible to have the form
'*explode/implode from various directions although this
'*code does not include that option.
'*
'* Call is ExplodeForm (or ImplodeForm) FormName, Movement

'
'Declarations



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



'User and GDI Functions for Explode/Implode to work



Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long


Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long


Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long


Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long


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


Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long


Declare Function SelectObject Lib "user32" (ByVal hdc As Long, ByVal hObject As Long) As Long


Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
#End If





Source Code:

'*The higher the "Movement", the slower the window
'*"explosion".

Sub ExplodeForm(f As Form, Movement As Integer)


Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect


formWidth = (myRect.Right - myRect.Left)


formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)


For i = 1 To Movement
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i

X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub



Public Sub ImplodeForm(f As Form, Direction As Integer, Movement As Integer, ModalState As Integer)

Dim myRect As RECT
Dim formWidth%, formHeight%, i%, X%, Y%, Cx%, Cy%
Dim TheScreen As Long
Dim Brush As Long
GetWindowRect f.hwnd, myRect


formWidth = (myRect.Right - myRect.Left)


formHeight = myRect.Bottom - myRect.Top
TheScreen = GetDC(0)
Brush = CreateSolidBrush(f.BackColor)


For i = Movement To 1 Step -1
Cx = formWidth * (i / Movement)
Cy = formHeight * (i / Movement)
X = myRect.Left + (formWidth - Cx) / 2
Y = myRect.Top + (formHeight - Cy) / 2
Rectangle TheScreen, X, Y, X + Cx, Y + Cy
Next i

X = ReleaseDC(0, TheScreen)
DeleteObject (Brush)
End Sub



 
The code given above describes how to explode and implode a window, which I don;t think is quite what you are asking for. However, what you are asking for - translucency and an ability to control it, i.e. alpha-channel blending - is relatively difficult to achieve in versions of Windows prior to W2000.

In W2000 you can set the WS_EX_LAYERED style bit for a window, and then use the UpdateLayeredWindow API or SetLayeredWindowAttributes.

I haven't written any code yet to exploit this, so can't give you an example here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top