API calls in VS.2005

  • Thread starter Thread starter Laurence
  • Start date Start date
L

Laurence

How does one go about making api calls in VS.2005 (VB.NET)?
Is there a book on API's for .NET like Dan's Appleman's API Book for VB?

How do I do the declares, and calls?

I am trying to do this:

Call SetWindowLong(mobjSplash.hwnd, GWL_EXSTYLE, WS_EX_LAYERED Or
Call GetWindowLong(mobjSplash.hwnd, GWL_EXSTYLE))
Call SetLayeredWindowAttributes(mobjSplash.hwnd, 0&, CByte(0), LWA_ALPHA)

I am trying to do this so that when I fade out a form, change its opacity
from 1 to 0 incrementally it won't flicker.

Laurence
 
Laurence said:
How does one go about making api calls in VS.2005 (VB.NET)?
Is there a book on API's for .NET like Dan's Appleman's API Book for VB?
How do I do the declares, and calls?

pinvoke.net has many many API interop declarations.

http://pinvoke.net/

-- Alan
 
Nice resource, Alan!

--

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Accept the Unexpected.
 
yes,
but when I set it to 99 when it was previously 1,
I get a real bad flicker.

Laurence
 
I finally figured it out.
I will post it so other people can see it.

What I was trying to do is fade in a form using the opacity property,
and Fade out a form using the opacity property.

I had a timer that increased or decreased the opacity property.

When the form was being shown and the opacity property was increased it
was very smooth.

But when I began to fade out the form, lowering the opacity property
initially from 1, I got real bad flicker.
This only occurs if the form has
a lot of controls on it. After the opacity property had been lowered
from the initial 1, and then lowered after that, the fading went smoothly.

Here is how to fix this.
I am not exactly sure why this works as I am new to VB.NET and
these API calls.

Since I was fading in the form, I put the

SetLayeredWindowAttributes(Me.Handle, 0, 255, LWA_ALPHA)

not in the load event, but in the code in the timer that increased
the opacity. I executed the SetLayeredWindowAttributes line above
after the opacity had reached 1.
Note, I also increased the third parameter to 255.
I did this because the form was coming up still transparent
even after the opacity of the form had reached 1.

Executing the above SetLayeredWindowAttributes caused the form
to be completely opaque.

Here is the code:


Public Class Form1

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal
bAlpha As Byte, ByVal dwFlags As Integer) As Integer

Private Const WS_EX_LAYERED As Integer = &H80000
Private Const LWA_ALPHA As Integer = &H2

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_LAYERED
Return cp
End Get
End Property

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' 0 = Completely Transparent
' 255 = Completely Opaque
SetLayeredWindowAttributes(Me.Handle, 0, 128, LWA_ALPHA)
End Sub

End Class
 
I finally figured it out.
I will post it so other people can see it.

What I was trying to do is fade in a form using the opacity property,
and Fade out a form using the opacity property.

I had a timer that increased or decreased the opacity property.

When the form was being shown and the opacity property was increased it
was very smooth.

But when I began to fade out the form, lowering the opacity property
initially from 1, I got real bad flicker.
This only occurs if the form has
a lot of controls on it. After the opacity property had been lowered
from the initial 1, and then lowered after that, the fading went smoothly.

Here is how to fix this.
I am not exactly sure why this works as I am new to VB.NET and
these API calls.

Since I was fading in the form, I put the

SetLayeredWindowAttributes(Me.Handle, 0, 255, LWA_ALPHA)

not in the load event, but in the code in the timer that increased
the opacity. I executed the SetLayeredWindowAttributes line above
after the opacity had reached 1.
Note, I also increased the third parameter to 255.
I did this because the form was coming up still transparent
even after the opacity of the form had reached 1.

Executing the above SetLayeredWindowAttributes caused the form
to be completely opaque.

Here is the code:


Public Class Form1

Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal
bAlpha As Byte, ByVal dwFlags As Integer) As Integer

Private Const WS_EX_LAYERED As Integer = &H80000
Private Const LWA_ALPHA As Integer = &H2

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or WS_EX_LAYERED
Return cp
End Get
End Property

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' 0 = Completely Transparent
' 255 = Completely Opaque
SetLayeredWindowAttributes(Me.Handle, 0, 128, LWA_ALPHA)
End Sub

End Class
 
Back
Top