Attribute VB_Name = "modAlphaBlending"
Option Explicit

Private Declare Function GetWindowLong Lib "user32.dll" Alias _
      "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
      As Long) As Long

Private Declare Function SetWindowLong Lib "user32.dll" Alias _
      "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
      ByVal dwNewLong As Long) As Long

Private Declare Function SetLayeredWindowAttributes Lib _
      "user32.dll" (ByVal hwnd As Long, ByVal crKey As Long, _
      ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000

Private Const LWA_ALPHA = &H2
Public Sub Form_SetStyle(ByVal hwnd As Long)

    Dim nStyle As Long

    nStyle = GetWindowLong(hwnd, GWL_EXSTYLE)

    nStyle = nStyle Or WS_EX_LAYERED
    SetWindowLong hwnd, GWL_EXSTYLE, nStyle
    
End Sub
Public Sub Form_SetAlphaValue(ByVal hwnd As Long, ByVal bAlpha As Byte)
    SetLayeredWindowAttributes hwnd, 0, bAlpha, LWA_ALPHA
End Sub
Public Sub Form_FadeIn(ByVal hwnd As Long, Optional ByVal iStep As Integer = 1)

  Dim iAlpha As Integer
    For iAlpha = 0 To 255 Step iStep
        SetLayeredWindowAttributes hwnd, 0, iAlpha, LWA_ALPHA
        DoEvents
    Next
End Sub
Public Sub Form_FadeOut(ByVal hwnd As Long, Optional ByVal iStep As Integer = 1)
Dim iAlpha As Integer

    For iAlpha = 255 To 0 Step -iStep
        SetLayeredWindowAttributes hwnd, 0, iAlpha, LWA_ALPHA
        DoEvents
    Next
End Sub
