Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET General

Post new topic   Reply to topic
UpdateLayeredWindow - help!
View previous topic :: View next topic  
Author Message
Latin4567
Newbie


Joined: 18 Sep 2005
Posts: 4
Location: US, Connecticut

PostPosted: Sep 18th, 2005 04:14 PM    Post subject: UpdateLayeredWindow - help! Reply with quote

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: [link]

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?

visual basic code:

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 to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
DoobieKeebler
Moderator


Joined: 17 Jun 2005
Posts: 254
Location: 181°15'2.003"W, 93°5'16.956"N

PostPosted: Sep 19th, 2005 03:33 PM    Post subject: Re: UpdateLayeredWindow - help! Reply with quote

Latin4567 wrote:
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: [link]


That link has gone 404, so I'm not really sure what you're trying to do.

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


My understanding is that you pass them ByRef.

Latin4567 wrote:
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


From the VB6 API Viewer:
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As long
End Type

Latin4567 wrote:
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?


I can help with some of this. Most of it, though, I couldn't tell you what the code does so I can't really correct it. (If I could I'd be a politician not a programmer.)
Latin4567 wrote:
Private Structure BLENDFUNCTION
Public BlendOp As Byte
Public BlendFlags As Byte
Public SourceConstantAlpha As Byte
Public AlphaFormat As Byte
End Structure


Structure isn't a keyword. I think you're looking for "Type". Also, leave out the Public before each "member" of the type. You can only declare the Type to be Public, Private, etc. Try this:

Public Type BLENDFUNCTION
BlendOp As Byte
BlendFlags As Byte
SourceConstantAlpha As Byte
AlphaFormat As Byte
End Type

Now, it looks like some of this is VB.Net. If you're trying this code in VB6 or earlier it just plain won't work. If you really are using VB.Net you may have better luck posting this in one of the VB.Net sections (it's currently in the VB6/5/4 API section).
_________________
Always take into account what a user would never ever in a million years do, because someone will.

"In theory, there's no difference between theory and practice. In practice, there is." -- Yogi Berra
Back to top
View user's profile Send private message
Latin4567
Newbie


Joined: 18 Sep 2005
Posts: 4
Location: US, Connecticut

PostPosted: Sep 19th, 2005 05:35 PM    Post subject: Reply with quote

dude, im using .NET beta... Structure is the replacement of type
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Latin4567
Newbie


Joined: 18 Sep 2005
Posts: 4
Location: US, Connecticut

PostPosted: Sep 19th, 2005 05:44 PM    Post subject: Reply with quote

hmm, the forum seems to have clipped the link... here it is

[link]
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic