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/de...eredwindow.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?

VB Code:
  1. Public Class Form1
  2.     Private Structure BLENDFUNCTION
  3.         Public BlendOp As Byte
  4.         Public BlendFlags As Byte
  5.         Public SourceConstantAlpha As Byte
  6.         Public AlphaFormat As Byte
  7.     End Structure
  8.  
  9.     'AlphaFormat flags
  10.     Private Const AC_SRC_OVER As Long = &H0&
  11.     Private Const AC_SRC_ALPHA = &H1
  12.  
  13.     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
  14.  
  15.     Private Const ULW_COLORKEY As Long = &H1&
  16.     Private Const ULW_ALPHA As Long = &H2&
  17.     Private Const ULW_OPAQUE As Long = &H4&
  18.  
  19.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  20.         Me.Opacity = 0.9 'set the opacity to somthing to its a layered window...
  21.  
  22.  
  23.     End Sub
  24.     Dim Graphics As Graphics
  25.     Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  26.         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...
  27.         e.Graphics.DrawImage(My.Resources.alpha, New Point(0, 0)) 'the multi-alpha-channel png image that we want the form to look like
  28.  
  29.  
  30.         Dim blend As BLENDFUNCTION
  31.         blend.AlphaFormat = AC_SRC_OVER
  32.         blend.SourceConstantAlpha = 0
  33.         blend.BlendFlags = 0
  34.         blend.BlendOp = AC_SRC_OVER
  35.  
  36.  
  37.  
  38.         If UpdateLayeredWindow(Me.Handle, 0&, 0&, 0&, 0&, e.Graphics.GetHdc(), 0&, blend, ULW_ALPHA) = True Then
  39.             MsgBox("it worked")
  40.         Else
  41.             MsgBox("there was an error") 'it is throwing errors at this point... i havnt gotten it to work yet
  42.         End If
  43.  
  44.     End Sub
  45. End Class