Private Sub changeFormEffect()
Dim W As Single, H As Single, cl As Long, ct As Long, cw As Long, ch As Long
Dim i As Integer, R As Long, Outer As Long, Inner As Long
' Excel affiche en points mais les API utilisent des pixels
' 1 pixel = 0.75 point / 1 point = 1.33 pixel
hWnd = FindWindow(vbNullString, Me.Caption)
W = Me.Width * 1.33: H = Me.Height * 1.33
If Status = 0 Then
frmRegion = CreateRectRgn(0, 0, W, H)
SetWindowRgn hWnd, frmRegion, True
Exit Sub
End If
frmRegion = CreateRectRgn(0, 0, 0, 0)
' Mesure des encadrements et hauteur de barre de titre
' X = (W - ScaleWidth) / 2 -> Généralement 3
' Y = H - X - ScaleHeight -> Généralement 22
Const X As Single = 3: Const Y As Single = 22
Const RGN_OR = 2 ' Crée l'union de régions combinées
Const RGN_DIFF = 4 ' Crée l'intersection de régions combinées
' Obtention de l'encadrement
If Status = 1 Then
Outer = CreateRectRgn(0, 0, W, H)
Inner = CreateRectRgn(X, Y, W - X, H - X)
CombineRgn frmRegion, Outer, Inner, RGN_DIFF
End If
' Combinaison des regions correpondant aux contrôles
For i = 0 To Me.Controls.Count - 1
If Me.Controls(i).Visible Then
ct = Y + (1.33 * Me.Controls(i).Top): ch = ct + (1.33 * Me.Controls(i).Height)
cl = X + (1.33 * Me.Controls(i).Left): cw = cl + (1.33 * Me.Controls(i).Width)
R = CreateRectRgn(cl, ct, cw, ch)
CombineRgn frmRegion, R, frmRegion, RGN_OR
End If
Next
SetWindowRgn hWnd, frmRegion, True
End Sub