|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
EFFETS DE FONDU ANIMÉS (TRANSPARENCE/OPACITÉ) SUR LES FENÊTRES
Information sur la source
Description
Le titre n'est pas très clair, alors voici ce qu'il y'a dans ce code : 3 fonctions qui font des fondus animés de votre fenêtre : elle apparait progressivement, de plus en plus transparent (ou l'inverse), si vous me comprenez. Il y'a 3 fonctions : FonduShow pour faire apparaitre une fenêtre en faisant un fondu FonduHide pour faire disparaitre la fenetre FonduChange pour changer la transparence mais en faisant un effet de fondu, c'est a dire progressif. J'avais fais ça dans un gros programme mais autant vous en faire profiter. Ne fonctionne que sous win2000, XP ou Server 2003 (logique à cause de la transparence) donc ne ralez pas les autres ;) c'est très simple à utiliser et j'ai très (mais très) rarement eu des bugs, alors que j'y utilise tous les jours, je vous met le code du module ici, c'est très simple à appeler
Source
- ' MODULE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
- Option Explicit
-
- ' L'instruction Sleep pour faire une pause dans le prog
- Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
-
- ' Pour la transparence de la fenêtre
- Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean
- Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
- Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
- Public Const WS_EX_LAYERED = &H80000
- Public Const LWA_COLORKEY = &H1
- Public Const LWA_ALPHA = &H2
- 'renvoie les styles de la fenêtre
- Public Const GWL_STYLE As Long = -16
- 'renvoie les styles étendus de la fenêtre
- Public Const GWL_EXSTYLE As Long = -20
- 'renvoie la fenêtre propriétaire de la fenêtre
- Public Const GWL_HWNDPARENT As Long = -8
-
- ' Active la transparence
- Public Function ActiveTransparence(Fenêtre As Form, ByVal AlphaInit As Byte)
- On Error GoTo Err
- SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
- ChangeTransparence Fenêtre, AlphaInit
- Exit Function
- Err:
- End Function
-
- ' Change la transparence
- Public Function ChangeTransparence(Fenêtre As Form, ByVal Alpha As Byte)
- On Error GoTo Err
- If Alpha = 0 Then DesactiveTransparence (Fenêtre): Exit Function
- SetLayeredWindowAttributes Fenêtre.hWnd, 0, Alpha, LWA_ALPHA
- Exit Function
- Err:
- End Function
-
- ' Supprime la transparence
- Public Function DesactiveTransparence(Fenêtre As Form)
- On Error Resume Next
- SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) - WS_EX_LAYERED
- End Function
-
- ' Fait un fondu de la fenêtre pour la faire disparaître
- ' Unload détermine si on décharge la fenêtre ou si on la cache juste
- Public Function FonduHide(Fen As Form, ByVal UnloadInEnd As Boolean, ByVal AlphaInit As Integer)
- On Error GoTo PasXP
- Dim T As Integer
- ' Sinon on active la transparence
- ActiveTransparence Fen, AlphaInit
- ' Puis on augmente a chaque fois sa transparence
- For T = AlphaInit To 1 Step -5
- ChangeTransparence Fen, T
- Sleep 1
- DoEvents
- Next T
- If UnloadInEnd = True Then Unload Fen
- Exit Function
- ' Si on a pas XP
- PasXP:
- If UnloadInEnd = True Then
- Unload Fen
- Else
- Fen.Visible = False
- End If
- End Function
-
- ' Fait un fondu de la fenêtre pour la faire montrer
- Public Function FonduShow(Fen As Form, ByVal AlphaFin As Integer)
- On Error GoTo PasXP
- Dim T As Integer
- ' Sinon on active la transparence mais la fenêtre est transparente a fond (donc invisible)
- ActiveTransparence Fen, 1
- Fen.Visible = True
- ' Puis on réduit a chaque fois sa transparence
- For T = 1 To AlphaFin Step 5
- ChangeTransparence Fen, T
- Sleep 1
- DoEvents
- Next T
- ' Puis si en final la fenêtre n'est plus transparente du tout (transparence à 255/255)
- ' alors on désactive la transparence
- If AlphaFin = 255 Then DesactiveTransparence Fen
- Exit Function
- ' Si on a pas XP
- PasXP:
- Fen.Visible = True
- End Function
-
- ' Change la transparence de la fenetre en faisant un fondu
- Public Function FonduChange(Fen As Form, ByVal AlphaInit As Byte, ByVal AlphaFin As Byte)
- On Error GoTo PasXP
- Dim T As Long
- Dim Delta As Long
- Delta = IIf(AlphaInit - AlphaFin < 0, 5, -5)
- ' On active la transparence
- Fen.Visible = True
- ActiveTransparence Fen, AlphaInit
- ' Puis on réduit ou augmente a chaque fois sa transparence
- For T = AlphaInit To AlphaFin Step Delta
- ChangeTransparence Fen, T
- Sleep 1
- DoEvents
- Next T
- ' Si la fenêtre n'est plus transparente, on la désactive
- If AlphaFin = 255 Then DesactiveTransparence Fen
- ' Si on a pas XP
- PasXP:
- End Function
' MODULE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit
' L'instruction Sleep pour faire une pause dans le prog
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Pour la transparence de la fenêtre
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
'renvoie les styles de la fenêtre
Public Const GWL_STYLE As Long = -16
'renvoie les styles étendus de la fenêtre
Public Const GWL_EXSTYLE As Long = -20
'renvoie la fenêtre propriétaire de la fenêtre
Public Const GWL_HWNDPARENT As Long = -8
' Active la transparence
Public Function ActiveTransparence(Fenêtre As Form, ByVal AlphaInit As Byte)
On Error GoTo Err
SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
ChangeTransparence Fenêtre, AlphaInit
Exit Function
Err:
End Function
' Change la transparence
Public Function ChangeTransparence(Fenêtre As Form, ByVal Alpha As Byte)
On Error GoTo Err
If Alpha = 0 Then DesactiveTransparence (Fenêtre): Exit Function
SetLayeredWindowAttributes Fenêtre.hWnd, 0, Alpha, LWA_ALPHA
Exit Function
Err:
End Function
' Supprime la transparence
Public Function DesactiveTransparence(Fenêtre As Form)
On Error Resume Next
SetWindowLong Fenêtre.hWnd, GWL_EXSTYLE, GetWindowLong(Fenêtre.hWnd, GWL_EXSTYLE) - WS_EX_LAYERED
End Function
' Fait un fondu de la fenêtre pour la faire disparaître
' Unload détermine si on décharge la fenêtre ou si on la cache juste
Public Function FonduHide(Fen As Form, ByVal UnloadInEnd As Boolean, ByVal AlphaInit As Integer)
On Error GoTo PasXP
Dim T As Integer
' Sinon on active la transparence
ActiveTransparence Fen, AlphaInit
' Puis on augmente a chaque fois sa transparence
For T = AlphaInit To 1 Step -5
ChangeTransparence Fen, T
Sleep 1
DoEvents
Next T
If UnloadInEnd = True Then Unload Fen
Exit Function
' Si on a pas XP
PasXP:
If UnloadInEnd = True Then
Unload Fen
Else
Fen.Visible = False
End If
End Function
' Fait un fondu de la fenêtre pour la faire montrer
Public Function FonduShow(Fen As Form, ByVal AlphaFin As Integer)
On Error GoTo PasXP
Dim T As Integer
' Sinon on active la transparence mais la fenêtre est transparente a fond (donc invisible)
ActiveTransparence Fen, 1
Fen.Visible = True
' Puis on réduit a chaque fois sa transparence
For T = 1 To AlphaFin Step 5
ChangeTransparence Fen, T
Sleep 1
DoEvents
Next T
' Puis si en final la fenêtre n'est plus transparente du tout (transparence à 255/255)
' alors on désactive la transparence
If AlphaFin = 255 Then DesactiveTransparence Fen
Exit Function
' Si on a pas XP
PasXP:
Fen.Visible = True
End Function
' Change la transparence de la fenetre en faisant un fondu
Public Function FonduChange(Fen As Form, ByVal AlphaInit As Byte, ByVal AlphaFin As Byte)
On Error GoTo PasXP
Dim T As Long
Dim Delta As Long
Delta = IIf(AlphaInit - AlphaFin < 0, 5, -5)
' On active la transparence
Fen.Visible = True
ActiveTransparence Fen, AlphaInit
' Puis on réduit ou augmente a chaque fois sa transparence
For T = AlphaInit To AlphaFin Step Delta
ChangeTransparence Fen, T
Sleep 1
DoEvents
Next T
' Si la fenêtre n'est plus transparente, on la désactive
If AlphaFin = 255 Then DesactiveTransparence Fen
' Si on a pas XP
PasXP:
End Function
Conclusion
On y appelle comme ça : Private Sub Form_Load() ' Fait apparaitre la form FonduShow Me, 255 End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) ' Fait disparaitre la form FonduHide Me, True, 0 End Sub et quand vous voulez vous pouvez utiliser : FonduChange Me, AlphaInitial, AlphaFinal Tout ceci est bien sur compatible avec les Unload Me, fermeture de la fenetre dans tout les sens, pas besoin de s'en soucier, tout est géré dans Form_Load et Form_Unload Pour vous aider à vous repérer : Transparent : 255 Opaque : 0 @ + MadMatt PS : des fois quand je fait disparaitre la form, j'ai un flash noir avant le fondu, dites moi si vous l'avez aussi et si vous avez une idée pour le faire disparaitre
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Historique
- 22 novembre 2005 18:29:28 :
- Ajout des mots clés
- 09 août 2006 15:30:52 :
- ajout de l'api "AnimateWindow"
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Effet de fondu a l ouverture/fermeture d une form [ par kaiserzeus ]
Salut,je cherche a pouvoir faire un fondu sur une form pour un spplash screen.Ca fait un moment que je cherche et je ne trouve pas mon bonheur en VB.E
Transparence & Opacité [ par kahlouni ]
Comment faire pour une Transparence & Opacité dans une image en utilisant un timer ?*un exemple si possible
images .... [ par jerexgrz ]
J'ai bien avancé mon jeu de strategie cependant, pour faire l'effet de transparence, j'hesite ! je pense convertir mes images pour les transformer en
Effet fondu sur Picturebox [ par alihome ]
Bonjour à tous,J'aimerais que quand je charge mon image à partir d'un fichier, elle apparraisse petit à petit, comme une fondu inverse.J'ai peut etre
opacité d'une image [ par DIJONCTER ]
bonjour à tous !Voila comment je fais pour modifier la transparence d'une picturebox (opaciter) dans vb 2005 avec des lignes de programme sans passer
Style de fenetres comme visual studio [ par alligo ]
Bonjour,Je crée une application qui doit gerer beaucoup de feuilles donc naturellement je me dit qua ca serait bien d'utiliser quelquechose comme le c
[VB 5 ] Format d'image transparence [ par Stalko ]
Bonjour, sous Visual Basic 5, le contrôle Image admet un nombre relativement faible de format. À ma connaissance, seuls les format *.ico et *.GIF pe
Besoin de lister les fenetres qui flash (blink) [ par werdDomain ]
Bonjours, jaurais besoin de lister les fenetres, dans la TaskBar, seux qui sont Orange et/ou qui flash (sous windows xp)Svp aidez moiMerci
[VB 2008] effet survol comme Vista [ par swan94 ]
Salut à tous,je voudrais savoir s'il existait (ou le cas échéant, comment le faire), un control qui, comme sur le panneau de config Vista, lorsque l'o
apparition picturebox en fondu [ par gsn ]
BonjourComment faire apparaitre un picturebox en fondu ????? Merci
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|