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
'Macht nur eine Farbe transparent
'Public Const LWA_COLORKEY = &H1
'Macht das ganze Fenster transparent
Private Const LWA_ALPHA = &H2
Public Sub Mache_Transparent(hWnd As Long, Rate As Byte)
Dim WinInfo As Long
WinInfo = GetWindowLong(hWnd, GWL_EXSTYLE)
If Rate < 255 Then
WinInfo = WinInfo Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, WinInfo
SetLayeredWindowAttributes hWnd, 0, Rate, LWA_ALPHA
Else
'Wenn als Rate 255 angegeben wird,
'so wird der Ausgangszustand wiederhergestellt
WinInfo = WinInfo Xor WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, WinInfo
End If
End Sub
Private Sub Command1_Click()
Mache_Transparent Me.hWnd, 175
End Sub