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
|
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Sub BackgroundTransparent(Objet As Object)
Dim CouleurBackground As Long
Dim hdcObjet As Long, RectFinal As Long, NewRect As Long
Dim x As Integer, y As Integer
On Error Resume Next
hdcObjet = GetWindowDC(Objet.hwnd)
CouleurBackground = GetPixel(hdcObjet, 0, 0)
If CouleurBackground = -1 Then Exit Sub
Objet.BackColor = CouleurBackground
RectFinal = CreateRectRgn(0, 0, Objet.width, Objet.height)
For y = 0 To Objet.height
For x = 0 To Objet.width
If GetPixel(hdcObjet, x, y) = CouleurBackground Then
NewRect = CreateRectRgn(x, y, x + 1, y + 1)
CombineRgn RectFinal, RectFinal, NewRect, 4
DeleteObject (NewRect)
End If
Next x
x = 0
Next y
SetWindowRgn Objet.hwnd, RectFinal, True
DeleteObject (RectFinal)
End Sub
|