Here's another way:
In a code module
In the formCode: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 Const GWL_STYLE = (-16) Private Const GWL_EXSTYLE = (-20) 'Requires Windows 2000 or later: Private Const WS_EX_LAYERED = &H80000 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 GetLayeredwindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Private Const LWA_COLORKEY = &H1 Private Const LWA_ALPHA = &H2 Public Sub MakeWindowTransparent(ByVal hWnd As Long, ByVal alphaAmount As Byte) Dim lStyle As Long lStyle = GetWindowLong(hWnd, GWL_EXSTYLE) lStyle = lStyle Or WS_EX_LAYERED SetWindowLong hWnd, GWL_EXSTYLE, lStyle SetLayeredWindowAttributes hWnd, 0, alphaAmount, LWA_ALPHA End Sub
Code:Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Dim iX As Long For iX = 10 To 255 Step 10 MakeWindowTransparent Me.hWnd, iX Me.Show DoEvents Sleep 200 Next End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim iX As Long For iX = 255 To 0 Step -10 MakeWindowTransparent Me.hWnd, iX DoEvents Sleep 200 Next End Sub




Reply With Quote