|
begin process at 2008 07 06 18:22:20
Derniers logiciels
|
Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
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 de la même categorie
Commentaires
Discussions en rapport avec ce code source
|
CalendriCode
| | | L | M | M | J | V | S | D |
| | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | | | |
|
Téléchargements
Logiciels à télécharger sur le même thème :
|
|