this is the code for tje fading effect of a form..

can anyone explain this code to me.. i really wanna learn this thing..

or

do you have any site or ebooks to read related to my problem??

I dont know what book should I read.

Is this all about WINDOWS API PROGRAMMING?

Dim Alpha
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
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 Sub Form_Load()
Dim Ret As Long
'Set the window style to 'Layered'
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
Timer1.Interval = 20

End Sub

Private Sub Timer1_Timer()
Alpha = Alpha + 1
If Alpha > 255 Then
Timer1.Enabled = False
Exit Sub
End If
'Set the opacity of the layered window
SetLayeredWindowAttributes Me.hWnd, 0, Alpha, LWA_ALPHA
End Sub

Recommended Answers

All 6 Replies

Yes, this is all about API...

The Private/Public Declare Function/Sub is the give away.

Now what this code does is it alters the forms opacity level, which means the higher the alpha value the more opaque or less transparent the form is.

As for learning API there are many sites out there like this one...

http://allapi.mentalis.org/


Good Luck

For example, i have a form that is color red and i also have a command buton that is color black?

how can i make the form be invisible while the command button is still shown?

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

and what are thos valriables and values??

and what are the &H2, (-20), &H8000, if i try to change it , my program was ruined..

They are constants defined to tell the dll that you call what to do.

As for red/black you need to search on using a mask color transparency vb6.

Good Luck

why does if i change the &H2 to &H4 it does not fade away? it become totally transparent..

See previous post!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.