• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

What am I missing? (forms fade in fade out)

I need help with this, I can't seem to find out what i'm missing in my vb code!
I got this code from a friend and I don't know whats wrong with it!
It keeps saying that "dummy" is not a expected varible or prosedure, but when I change it to "dummy.*" it says for me to remove the ()
I don't know what to do!
anyway, heres the code...

This goes in the form...

Private Sub Form_Load()
' DROPSHADOW Win2000/XP
ApplyDropShadow Me.hwnd
'FULLY TRANSLUCENT ON WIN 2000/XP
dummy = TranslucentForm(Me, 0)
'FADING IN
For i = 0 To 255 Step 5
dummy = TranslucentForm(Me, CByte(i))
DoEvents
Me.Show
Next
'FULLY OPAQUE
dummy = TranslucentForm(Me, 255)
End Sub

This goes in a module witch I do not know what to name it...

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) _
As Long
Private Declare Function SetLayeredWindowAttributes Lib _
"user32" (ByVal hwnd As Long, ByVal crKey As Long, _
ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Declare Function GetClassLong Lib "user32.dll" Alias "GetClassLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Public Sub ApplyDropShadow(hwnd As Long)
On Error Resume Next
SetClassLong hwnd, -26, GetClassLong(hwnd, -26) Or &H20000
End Sub

Public Function TranslucentForm(frm As Form, _
TranslucenceLevel As Byte) As Boolean
On Error Resume Next
SetWindowLong frm.hwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes frm.hwnd, 0, TranslucenceLevel, _
LWA_ALPHA
TranslucentForm = Err.LastDllError = 0
End Function
0
chrisyroid
Asked:
chrisyroid
  • 4
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You're not using the return value of TranslucentForm() so I would get rid of the "dummy" variable...

Change:

    dummy = TranslucentForm(Me, 0)

to:

    TranslucentForm Me, 0

Follow the pattern to change the other to calls to TranslucentForm() as well.

0
 
chrisyroidAuthor Commented:
the form is fading in too fast, is there anyway to change that?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You could make a call to the Sleep() API to slow down your loop:

Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

...

    For i = 0 To 255 Step 5
        dummy = TranslucentForm(Me, CByte(i))
        DoEvents
        Me.Show
        Sleep 25
    Next
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
chrisyroidAuthor Commented:
could I hook it up to a timer?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sure...something like...

' --------------------
'   Form1
' --------------------
Option Explicit

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib "user32" _
    (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
   
Private Declare Function GetClassLong Lib "user32.dll" Alias "GetClassLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private alpha As Integer

Private Sub Form_Load()
    Timer1.Enabled = False
    alpha = 1
    Timer1.Interval = 15
   
    ' DROPSHADOW Win2000/XP
    ApplyDropShadow Me
    'FULLY TRANSLUCENT ON WIN 2000/XP
    TranslucentForm Me, 0
   
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    If alpha < 255 Then
        alpha = alpha + 2
        TranslucentForm Me, CByte(alpha)
    Else
        Timer1.Enabled = False
        TranslucentForm Me, 255
    End If
End Sub

Private Sub ApplyDropShadow(frm As Form)
    On Error Resume Next
    SetClassLong frm.hWnd, -26, GetClassLong(frm.hWnd, -26) Or &H20000
End Sub

Private Sub TranslucentForm(frm As Form, TranslucenceLevel As Byte)
    On Error Resume Next
    SetWindowLong frm.hWnd, GWL_EXSTYLE, WS_EX_LAYERED
    SetLayeredWindowAttributes frm.hWnd, 0, TranslucenceLevel, LWA_ALPHA
End Sub
0
 
chrisyroidAuthor Commented:
thanks. please close this
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Close it by clicking the "Accept" button next to the comment that answered your question...   =)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now