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
| Private Structure BLENDFUNCTION
Dim BlendOp As Byte
Dim BlendFlags As Byte
Dim SourceConstantAlpha As Byte
Dim AlphaFormat As Byte
End Structure
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Private Declare Function UpdateLayeredWindow Lib "user32.dll" Alias "GetClassLongA" (ByVal hWnd As IntPtr,hdcDst As IntPtr, pptDst As Point,psize As Size, hdcSrc As IntPtr,pptSrc As Point, crKey As Integer,pblend As BLENDFUNCTION, dwFlags As Integer) As Boolean
Private Declare Auto Function SetWindowLong Lib "User32.Dll" (ByVal hWnd As IntPtr,ByVal nIndex As Integer,ByVal dwNewLong As Integer) As Integer
'Le code suivant est un traduction du code delphi posté sur le forum de developpez.com
'J'ai postionné ce code dans le chargement de ma form
Dim bitmaptest As Bitmap = Image.FromFile("c:\test77.png")
SetWindowLong(Me.Handle, GWL_EXSTYLE,WS_EX_LAYERED)
Dim screenDc As IntPtr = nothing
Dim memDc As IntPtr = nothing
Dim hBitmap As IntPtr = IntPtr.Zero
Dim oldBitmap As IntPtr = IntPtr.Zero
hBitmap = bitmaptest.GetHbitmap(Color.FromArgb(0)) 'grab a GDI handle from this GDI+ bitmap
Dim size As Size = new Size(bitmaptest.Width, bitmaptest.Height)
Dim PointSource As Point = new Point(0, 0)
Dim topPos As Point = new Point(Left, Top)
Dim blend As BLENDFUNCTION = new BLENDFUNCTION()
blend.BlendOp = 0
blend.BlendFlags = 0
blend.SourceConstantAlpha = 255
blend.AlphaFormat = 1
Dim bResultat As Boolean = UpdateLayeredWindow(Me.Handle, screenDc, topPos, size, memDc, pointSource, 0, blend, 1)
MessageBox.show(bResultat) |
Partager