Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Général VBA > Contribuez
Contribuez Proposez vos articles, cours, tutoriels, faq, codes sources, astuces pour VBA
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 28/09/2006, 07h55   #1
Responsable Visual Basic
 
Avatar de bbil
 
Inscription : juin 2003
Messages : 11 773
Détails du profil
Informations personnelles :
Âge : 45
Localisation : France, Ariège (Midi Pyrénées)

Informations forums :
Inscription : juin 2003
Messages : 11 773
Points : 16 854
Points : 16 854
Envoyer un message via Skype™ à bbil
Par défaut [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
Fichiers attachés
Type de fichier : zip transparent.zip (18,5 Ko, 135 affichages)
bbil est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/09/2006, 08h24   #2
Responsable Visual Basic
 
Avatar de ThierryAIM
 
Homme Thierry
Inscription : septembre 2002
Messages : 3 670
Détails du profil
Informations personnelles :
Nom : Homme Thierry
Âge : 49
Localisation : France, Rhône (Rhône Alpes)

Informations professionnelles :
Secteur : Industrie

Informations forums :
Inscription : septembre 2002
Messages : 3 670
Points : 5 672
Points : 5 672
la transparence d'une form est déjà dans la FAQ VB

http://vb.developpez.com/faq/?page=Form#transparence

Je peux compléter avec la transparence d'une couleur
__________________
Vous vous posez une question, la réponse est peut-être ici :
Toutes les FAQs VB
Les Cours et Tutoriels VB6/VBScript
Les Sources VB6


Je ne réponds pas aux questions techniques par MP. Utilisez les forums. Merci de votre compréhension

MioSkins.org : le site de référence pour GPS et PDA Mitac MIO
iPHONIX.fr : le must francophone des infos pour iPhone, iPad, ...
ThierryAIM est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h28.


 
 
 
 
Partenaires

Hébergement Web