Sub ShowForm()
UserForm1.Show
End Sub
Option Explicit
Private Declare Function GetActiveWindow Lib "USER32" () As Long
Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal lngWinIdx As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal lngWinIdx As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "USER32" _
(ByVal hWnd As Long, _
ByVal crKey As Integer, _
ByVal bAlpha As Integer, _
ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC
Dim hWnd As Long
Dim Transparancy As Integer
Dim Running As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
Running = True
Call Transparency
End Sub
Private Sub Transparency()
Dim MyTimer As Double
DoEvents
MyTimer = Timer
Do
Do
Loop While Timer - MyTimer < 0.07
MyTimer = Timer
Transparancy = Transparancy - 1
If Transparancy < 0 Then
Unload Me
Else
Call SemiTransparent(Application.WorksheetFunction.Min(Transparancy, 100))
End If
DoEvents
Loop While Running
End Sub
Private Sub SemiTransparent(ByVal intLevel As Integer)
Dim lngWinIdx As Long
hWnd = GetActiveWindow
lngWinIdx = GetWindowLong(hWnd, GWL_EXSTYLE)
SetWindowLong hWnd, GWL_EXSTYLE, lngWinIdx Or WS_EX_LAYERED
SetLayeredWindowAttributes hWnd, 0, (255 * intLevel) / 100, LWA_ALPHA
End Sub
Private Sub UserForm_Initialize()
Transparancy = 120
Call SemiTransparent(100)
DoEvents
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Running = False
End Sub
|