Private Const LWA_COLORKEY As Long = &H1
Private Const GWL_EXSTYLE As Long = (-20&)
Private Const WS_EX_LAYERED As Long = &H80000
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 SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Sub CutFormFromColor(ByVal lFormHandle As Long, Optional ByVal lColor As OLE_COLOR = &HFF00FF)
Dim lRet As Long
lRet = GetWindowLong(lFormHandle, GWL_EXSTYLE) Or WS_EX_LAYERED
Call SetWindowLong(lFormHandle, GWL_EXSTYLE, lRet)
Call SetLayeredWindowAttributes(lFormHandle, lColor, 0&, LWA_COLORKEY)
End Sub
' EXEMPLE D'UTILISATION
' =====================
' pensez bien à :
' *mettre la propriété BorderStyle à 0
' *applique cette image : http://www.enregistrersous.com/images2/99264686220080507110006.bmp
' *redimentionner la fenêtre au plus proche de l'image ou changer la couleur de fond de la form
Option Explicit
'
'
' *- DéCOUPE AU CHARGEMENT -*
Private Sub Form_Load()
Call CutFormFromColor(Me.hWnd, 128&)
End Sub
'
' *- QUITTE AU CLICK -*
Private Sub Form_Click()
Unload Me
End Sub