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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Option Explicit
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function InvalidateRectLong Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Private Const WS_EX_TRANSPARENT = &H20&
Private Const GWL_EXSTYLE = (-20)
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Const TRANSPARENT = 1
'bouton transparence
Private Sub CommandButton1_Click()
FrameTransparent Frame1, True '(2d argument true=cadre;false= pas de cadre
End Sub
Private Sub FrameTransparent(ByVal fraThis As Control, Optional border As Boolean = False)
Dim lehwnd As Long, lExStyle As Long, c As Control
If border = True Then
Set c = fraThis.Controls.Add("forms.Label.1", "cadre")
c.Move 0, 0, fraThis.Width - 2, fraThis.Height - 2
c.BackStyle = 0: c.BorderStyle = 1: c.BorderColor = fraThis.BorderColor:
End If
lehwnd = fraThis.[_GethWnd]
lExStyle = GetWindowLong(lehwnd, GWL_EXSTYLE)
lExStyle = lExStyle Or WS_EX_TRANSPARENT
SetWindowLong lehwnd, GWL_EXSTYLE, lExStyle
SetBkMode GetDC(lehwnd), TRANSPARENT ' cette ligne bloquée ou pas la frame est transparente
SetWindowPos lehwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED
InvalidateRectLong lehwnd, vbNull, True
DoEvents
fraThis.ZOrder
fraThis.Top = fraThis.Top + 1 '******* lire pourquoi cette étrange manoeuvre ca arrive quand on utilise le GWL_EXSTYLE
fraThis.Top = fraThis.Top - 1 '******* à la suite du code
For Each c In Frame1.Controls
c.ZOrder
Next
If border = True Then fraThis.cadre.ZOrder 1 'important il doit etre au dessus au au depart!!!!!
End Sub
Private Sub Label1_Click()
MsgBox "coucou"
End Sub |