Accueil > > > EFFET DE TRANSPARENCE
EFFET DE TRANSPARENCE
Information sur la source
Description
Affichage d'une fenêtre avec un effet de transparence
Source
-
- '------------------------- API's -------------------------
- Private Declare Function SetLayeredWindowAttributes Lib "user32" _
- (ByVal hwnd As Long, _
- ByVal crKey As Long, _
- ByVal bAlpha As Long, _
- 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
-
- Private Declare Function GetWindowLong Lib "user32" _
- Alias "GetWindowLongA" _
- (ByVal hwnd As Long, _
- ByVal nIndex As Long) As Long
-
- Private Declare Function UpdateWindow Lib "user32" _
- (ByVal hwnd As Long) As Long
-
- Private Const GWL_EXSTYLE As Long = (-20)
- Private Const WS_EX_LAYERED As Long = &H80000
- Private Const LWA_ALPHA As Long = &H2
-
- Private OpApplied As Byte 'Opacité appliquée
-
- '------------------------- Events ------------------------
-
- Private Sub Form_Load()
-
- 'Opacité initiale de 0 (100% de transparence)
- 'pour éviter un artefact visuel.
- Call SetTransparency(Me.hwnd, 0)
- 'Largeur minimum (commande "Print on click")
- If Me.Width < 5160 Then Me.Width = 5160
-
- End Sub
-
- Private Sub Form_Activate()
-
- 'Affichage de la feuille avec effet de transparence
- 'et une raison de progression (Offset) de 1.
- Call setFadeIn(Me.hwnd, 1)
-
- End Sub
-
- Private Sub Command1_Click()
-
- 'Crée un effet de transparence
- Call SetTransparency(Me.hwnd, 127)
- 'Affiche le pourcentage de transparence
- Print vbCr & Space(6) & "Pourcentage de transparence : 100 - ((127/255)*100) = 50,2%"
- Command1.Enabled = False
-
- End Sub
-
- Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
-
- 'Effacement de la feuille avec effet de transparence
- 'et une raison de progression (Offset) de 3.
- Call setFadeOut(Me.hwnd, 3)
-
- End Sub
-
- '---------------------- Procedures -----------------------
-
- Sub setFadeIn(lngHWnd As Long, Offset As Byte)
-
- Dim Attrib As Long
- Dim Opacity As Byte
-
- If 255 Mod Offset = 0 Then
- Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
- Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
- Do
- Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
- Call UpdateWindow(lngHWnd)
- Opacity = Opacity + Offset
- Loop While Opacity <= 255 - Offset
- Else
- Call MsgBox(vbCr & "Valeur incorrecte !" & vbCr & vbCr & _
- "Veuillez choisir un diviseur de 255 (1, 3, 5, 15, 17 etc.)" & Space(12) & vbCr & _
- "comme raison de la progression arithmétique.", vbExclamation, " Affichage progressif (alpha blending)")
- Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), 255, LWA_ALPHA)
- End If
-
- End Sub
-
- Sub SetTransparency(lngHWnd As Long, Opacity As Byte)
-
- Dim Attrib As Long
- Dim RetVal As Boolean
-
- Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
- Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
- RetVal = SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
- OpApplied = Opacity
- If Not RetVal Then
- Call MsgBox(vbCr & "Echec fonctionnel !" & vbCr & vbCr & _
- "Pour information, l'API ""SetLayeredWindowAttributes"" est implémenté" & Space(12) & vbCr & _
- "depuis la version 2000 de Windows et n'est pas supporté par Win9x/ME.", vbCritical, " Effet de transparence (alpha blending)")
- End
- End If
-
- End Sub
-
- Sub setFadeOut(lngHWnd As Long, Offset As Byte)
-
- Dim Attrib As Long
- Dim Opacity As Byte
-
- If 255 Mod Offset = 0 Then
- Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
-
- Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
- 'A cause du bouton "Command1"
- Opacity = IIf(OpApplied > 0, OpApplied - (OpApplied Mod Offset), 255)
- Do
- Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
- Call UpdateWindow(lngHWnd)
- Opacity = Opacity - Offset
- Loop While Opacity > 0
- Else
- Call MsgBox(vbCr & "Valeur incorrecte !" & vbCr & vbCr & _
- "Veuillez choisir un diviseur de 255 (1, 3, 5, 15, 17 etc.)" & Space(12) & vbCr & _
- "comme raison de la progression arithmétique.", vbExclamation, " Effacement progressif (alpha blending)")
- End If
-
- End Sub
-
- '---------------------------------------------------------
'------------------------- API's -------------------------
Private Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hwnd As Long, _
ByVal crKey As Long, _
ByVal bAlpha As Long, _
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
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function UpdateWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_LAYERED As Long = &H80000
Private Const LWA_ALPHA As Long = &H2
Private OpApplied As Byte 'Opacité appliquée
'------------------------- Events ------------------------
Private Sub Form_Load()
'Opacité initiale de 0 (100% de transparence)
'pour éviter un artefact visuel.
Call SetTransparency(Me.hwnd, 0)
'Largeur minimum (commande "Print on click")
If Me.Width < 5160 Then Me.Width = 5160
End Sub
Private Sub Form_Activate()
'Affichage de la feuille avec effet de transparence
'et une raison de progression (Offset) de 1.
Call setFadeIn(Me.hwnd, 1)
End Sub
Private Sub Command1_Click()
'Crée un effet de transparence
Call SetTransparency(Me.hwnd, 127)
'Affiche le pourcentage de transparence
Print vbCr & Space(6) & "Pourcentage de transparence : 100 - ((127/255)*100) = 50,2%"
Command1.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'Effacement de la feuille avec effet de transparence
'et une raison de progression (Offset) de 3.
Call setFadeOut(Me.hwnd, 3)
End Sub
'---------------------- Procedures -----------------------
Sub setFadeIn(lngHWnd As Long, Offset As Byte)
Dim Attrib As Long
Dim Opacity As Byte
If 255 Mod Offset = 0 Then
Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
Do
Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
Call UpdateWindow(lngHWnd)
Opacity = Opacity + Offset
Loop While Opacity <= 255 - Offset
Else
Call MsgBox(vbCr & "Valeur incorrecte !" & vbCr & vbCr & _
"Veuillez choisir un diviseur de 255 (1, 3, 5, 15, 17 etc.)" & Space(12) & vbCr & _
"comme raison de la progression arithmétique.", vbExclamation, " Affichage progressif (alpha blending)")
Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), 255, LWA_ALPHA)
End If
End Sub
Sub SetTransparency(lngHWnd As Long, Opacity As Byte)
Dim Attrib As Long
Dim RetVal As Boolean
Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
RetVal = SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
OpApplied = Opacity
If Not RetVal Then
Call MsgBox(vbCr & "Echec fonctionnel !" & vbCr & vbCr & _
"Pour information, l'API ""SetLayeredWindowAttributes"" est implémenté" & Space(12) & vbCr & _
"depuis la version 2000 de Windows et n'est pas supporté par Win9x/ME.", vbCritical, " Effet de transparence (alpha blending)")
End
End If
End Sub
Sub setFadeOut(lngHWnd As Long, Offset As Byte)
Dim Attrib As Long
Dim Opacity As Byte
If 255 Mod Offset = 0 Then
Attrib = GetWindowLong(lngHWnd, GWL_EXSTYLE)
Call SetWindowLong(lngHWnd, GWL_EXSTYLE, Attrib Or WS_EX_LAYERED)
'A cause du bouton "Command1"
Opacity = IIf(OpApplied > 0, OpApplied - (OpApplied Mod Offset), 255)
Do
Call SetLayeredWindowAttributes(lngHWnd, RGB(0, 0, 0), Opacity, LWA_ALPHA)
Call UpdateWindow(lngHWnd)
Opacity = Opacity - Offset
Loop While Opacity > 0
Else
Call MsgBox(vbCr & "Valeur incorrecte !" & vbCr & vbCr & _
"Veuillez choisir un diviseur de 255 (1, 3, 5, 15, 17 etc.)" & Space(12) & vbCr & _
"comme raison de la progression arithmétique.", vbExclamation, " Effacement progressif (alpha blending)")
End If
End Sub
'---------------------------------------------------------
Conclusion
Tous niveaux
Copier le code source dans une feuille "Form1" comprenant un bouton "Command1".
Historique
- 16 juillet 2004 16:45:58 :
- "Onshow" Opacity=0 pour éviter un artefact d'affichage de la fenêtre
- 19 juillet 2004 09:55:27 :
- MAJ, ajouts :
- commentaires,
- opacité appliquée,
- raison de la progression,
- messages d'erreurs,
- fichier zip du projet.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
GESTION D'EXCEPTION AVEC LES TASKSGESTION D'EXCEPTION AVEC LES TASKS par richardc
Nous avons vu dans un précédent article comment utiliser Task pour effectuer des opérations dans un autre thread.
Malheureusement, comme tout le monde n'est pas parfait, il se peut que cette exécution se passe mal et qu'une exception se produise.
La...
Cliquez pour lire la suite de l'article par richardc DéMARRONS AVEC LES TASKSDéMARRONS AVEC LES TASKS par richardc
Que vous le vouliez ou non, le développement multi-tâche est maintenant une obligation pour toute nouvelle application. Il est donc vital d'en comprendre les mécanismes et de s'y mettre le plus tôt possible.
En attendant le .NET Framework 4.5 avec le...
Cliquez pour lire la suite de l'article par richardc SLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPSSLIDE & DéMO TECHDAYS 2012 - FAST & FURIOUS XAML APPS par Vko
Retrouvez les slides et les démo de ma session Fast & Furious XAML Apps. A ceux qui se posent la question : "est-ce que le code de la DataGrid est disponible?", je vous répondrais "pas encore". Je vais mettre en place un projet codeplex pour part...
Cliquez pour lire la suite de l'article par Vko XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : VITESSERE : VITESSE par ucfoutu
Cliquez pour lire la suite par ucfoutu MACRO VBA EXCELMACRO VBA EXCEL par sigma17
Cliquez pour lire la suite par sigma17 VITESSEVITESSE par ossama261988
Cliquez pour lire la suite par ossama261988
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|