|
-
Jan 3rd, 2007, 06:58 AM
#1
Thread Starter
Addicted Member
Fade and Opacity
Hi,
Two questions:
1) How do i change the opacity of a form
2) How can i make a form fade in?
Any help would be great!
Thanks,
Ross
-
Jan 3rd, 2007, 07:11 AM
#2
Lively Member
Re: Fade and Opacity
Use this API code:
VB Code:
‘In general declarations
Dim intA as integer
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 TmrTimer_timer
If intA <> 255 Then
IntA = intA + 1
Else
tmrTimer.enabled = false
End If
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'Set the opacity of the layered window to intA
SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
End Sub
End Sub
If, somehow, I help you, please rate the post using the scales icon in the left bar <----  .
Please Use Naming Conventions in your projects! ------\/
http://www.visibleprogress.com/vb_na...onventions.htm
Me to Brother
-Hey, look at this avater I made in about 5 seconds
-What, morrisons?
-AGHHHHHH
-
Jan 3rd, 2007, 08:52 AM
#3
Junior Member
Re: Fade and Opacity
 Originally Posted by Moneybucks
Use this API code:
VB Code:
‘In general declarations
Dim intA as integer
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 TmrTimer_timer
If intA <> 255 Then
IntA = intA + 1
Else
tmrTimer.enabled = false
End If
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'Set the opacity of the layered window to intA
SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
End Sub
End Sub
hey dude i modify your code because the form was showing and before disapear... and after was showing again! now the form is show with fade! i thing that are so be good now
look this
VB Code:
Option Explicit
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
Const LWA_COLORKEY = &H2
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Dim intA As Integer
Private Sub Form_Load()
Form1.Visible = False
End Sub
Private Sub TmrTimer_timer()
If intA <> 255 Then
intA = intA + 1
If intA > 1 Then
Form1.Visible = True
End If
Else
TmrTimer.Enabled = True
End If
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'Set the opacity of the layered window to intA
SetLayeredWindowAttributes Me.hWnd, 0, intA, LWA_ALPHA
End Sub
[VBCODE]on error go to VBForums[/VBCODE]
-
Jan 3rd, 2007, 09:10 AM
#4
Re: Fade and Opacity
there's no need to constantly set the GWL_EXSTYLE, I'd do something more like:
VB Code:
Option Explicit
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 Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Sub Form_Load()
Dim lStyle As Long
lStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
SetWindowLong Me.hWnd, GWL_EXSTYLE, lStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.hWnd, 0&, 0&, LWA_ALPHA
Me.Show
Timer1.Enabled = True
End Sub
Private Sub Timer1_timer()
Static lAlpha As Long
lAlpha = lAlpha + 3
SetLayeredWindowAttributes Me.hWnd, 0&, lAlpha, LWA_ALPHA
If lAlpha = 255 Then Timer1.Enabled = False
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|