UpdateLayeredWindow - help!

Latin4567

New member
Joined
Sep 18, 2005
Messages
3
Location
US, Connecticut
Programming Experience
1-3
I am trying to accomplish an effect similar to programs like Konfabulator and DesktopX which use the UpdateLayeredWindow API to achieve vista-like window layering. I need to create a translucent form with ranging alpha values based on a png image. So basically, I have want to be able to create custom forms which support alpha-blending directly to the desktop. (I am NOT trying to simply change the opacity of a form).

MSDN Library briefly explains in the documentation for the UpdateLayeredWindow API how to do this but I cant get it to work, mostly because my lack of experience with api's. Perhaps someone can make sense of it: http://msdn.microsoft.com/library/d...yeredwindow.asp

So here's my question(s):

How do you use pointers (IntPtr) to pass objects to an API

How do you pass objects like the RECT structure to an API, because visual basic doesnt have a RECT structure... it has the rectangle type

Here is my code... The api is encountering errors so it is returning false... Could someone please help me fix this/get it to work?

Public Class Form1
Private Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
End Structure

'AlphaFormat flags
Private Const AC_SRC_OVER As Long = &H0&
Private Const AC_SRC_ALPHA = &H1

Private Declare Function UpdateLayeredWindow Lib "user32" Alias "UpdateLayeredWindow" (ByVal hwnd As Long, ByVal hdcDst As Long, ByVal pptDst As Object, ByVal psize As Object, ByVal hdcSrc As Long, ByVal pptSrc As Object, ByVal crKey As Long, ByVal pblend As BLENDFUNCTION, ByVal dwFlags As Long) As Long

Private Const ULW_COLORKEY As Long = &H1&
Private Const ULW_ALPHA As Long = &H2&
Private Const ULW_OPAQUE As Long = &H4&

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Opacity = 0.9 'set the opacity to somthing to its a layered window...


End Sub
Dim Graphics As Graphics
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.Clear(Color.Transparent) 'I cant figure out how to create a graphics objet because they have no constructors so I am using the form's graphics object instead...
e.Graphics.DrawImage(My.Resources.alpha, New Point(0, 0)) 'the multi-alpha-channel png image that we want the form to look like


Dim blend As BLENDFUNCTION
blend.AlphaFormat = AC_SRC_OVER
blend.SourceConstantAlpha = 0
blend.BlendFlags = 0
blend.BlendOp = AC_SRC_OVER



If UpdateLayeredWindow(Me.Handle, 0&, 0&, 0&, 0&, e.Graphics.GetHdc(), 0&, blend, ULW_ALPHA) = True Then
MsgBox("it worked")

Else
MsgBox("there was an error") 'it is throwing errors at this point... i havnt gotten it to work yet
End If

End Sub
End Class
 
Back
Top