Rendre une form transparente / translucide

Contenu du snippet

Private Const GWL_EXSTYLE As Long = (-20)
Private Const LWA_ALPHA As Long = &H2
Private Const WS_EX_LAYERED As Long = &H80000
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As  Long
Public Sub SetFormTransparence(ByVal sUserformCaption As String, ByVal bTransparent As Boolean)
    Dim lHwnd  As Long
    Dim lStyle As Long
    lHwnd = FindWindowA("Thunder" & IIf(Application.Version Like "8*", "X", "D") & "Frame", sUserformCaption)
    If lHwnd <> 0 Then
        lStyle = GetWindowLong(lHwnd, GWL_EXSTYLE)
        If lStyle <> (lStyle Or WS_EX_LAYERED) Then Call SetWindowLong(lHwnd,  GWL_EXSTYLE, lStyle Or WS_EX_LAYERED)
        
        Call SetLayeredWindowAttributes(lHwnd,  0&, IIf(bTransparent, 127, 255), LWA_ALPHA)
    End If
End Sub

Compatibilité : VBA

Disponible dans d'autres langages :

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.