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
Printable View
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
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
Quote:
Originally Posted by Moneybucks
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
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