1 pièce(s) jointe(s)
[Sources][VBA] Transparence de fenêtre
a fonction API SetLayeredWindowAttributes, permet de modifier la transparence
des fenêtres windows ..
déclaration des fonctions à mettre dans un module standard:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
'
' APIs gestion des fenêtres transparentes
'
Public Const GWL_EXSTYLE As Long = (-20)
Public Const WS_EX_LAYERED As Long = &H80000
Public Const LWA_COLORKEY As Long = &H1
Public Const LWA_ALPHA As Long = &H2
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) As Long
' Pour Excel ou Word, FindWindow.. afin de déterminer l'handle de la fenêtre
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long |
rendre une fenêtre transparante
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
Private Sub UserForm_Initialize()
Dim MeHwnd As Long
'Recupere le handle de la fenêtre
MeHwnd = FindWindowA(vbNullString, Me.Caption)
'Rajoute l'attribut transparent à la fenêtre..
SetWindowLong MeHwnd, GWL_EXSTYLE, _
GetWindowLong(MeHwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
'Definie la transparence de la fenêtre
'125 = Taux de transparence de 0 à 255
SetLayeredWindowAttributes MeHwnd, 0, 125, LWA_ALPHA
End Sub |
SetLayeredWindowAttributes permet aussi de rendre une couleur transparente :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
Private Sub UserForm_Initialize()
Dim MeHwnd As Long
'Recupere le handle de la fenêtre
MeHwnd = FindWindowA(vbNullString, Me.Caption)
'Rajoute l'attribut transparent à la fenêtre..
SetWindowLong MeHwnd, GWL_EXSTYLE, _
GetWindowLong(MeHwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
Me.BackColor = vbBlue 'Passe la couleur de fond en bleu avant de la
'rendre tansparante
SetLayeredWindowAttributes MeHwnd, vbBlue, 0, LWA_COLORKEY
End Sub |
ci-joint un exemple sous excel 2000
Changer la couleur transparente
Bonjour, je voulais savoir comment je peux changer la transparence d'une couleur à 60% au lieu de ce que l'exemple montre qui est à la pleine transparence ou 0. merci!
Code:
1 2 3 4 5 6 7 8 9
| ' Rendre invisible une couleur
Private Sub CdbJaune_Click()
' Pour mémoire vbYellow = &Hffff& = 65535
SetLayeredWindowAttributes MeHwnd, vbYellow, 0, LWA_COLORKEY
End Sub
Private Sub CdeBleu_Click()
'Pour mémoire : vbBlue = &HFF0000
SetLayeredWindowAttributes MeHwnd, vbBlue, 0, LWA_COLORKEY
End Sub |