Solved

splash screen using a transparent png with vb.net

Posted on 2014-11-10
2
285 Views
Last Modified: 2014-11-11
Im trying to do a splash screen using a transparent png with vb.net

I found this amazing class(http://www.vcskicks.com/splash-screen.php) to allow to do  a splash screen using  a transparent png with shadow

After rewrite the code to vb.net it works without problems, but if I try to put a label or button for example thouse controls are not painted in the form.

I suposse that I made a mistake when I translate the class to vb.

What Im doing wrong????

This is my code:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public NotInheritable Class SplashScreen1
    Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        UpdateFormDisplay(Me.BackgroundImage)
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        'Call our drawing function
        UpdateFormDisplay(Me.BackgroundImage)
    End Sub

    Public Sub UpdateFormDisplay(ByVal backgroundImage As Image)
        Dim screenDc As IntPtr = api1.GetDC(IntPtr.Zero)
        Dim memDc As IntPtr = api1.CreateCompatibleDC(screenDc)
        Dim hBitmap As IntPtr = IntPtr.Zero
        Dim oldBitmap As IntPtr = IntPtr.Zero
        Try
            'Display-image
            Dim bmp As Bitmap = New Bitmap(backgroundImage)
            hBitmap = bmp.GetHbitmap(Color.FromArgb(0))
            'Set the fact that background is transparent
            oldBitmap = api1.SelectObject(memDc, hBitmap)
            'Display-rectangle
            Dim size As Size = bmp.Size
            Dim pointSource As Point = New Point(0, 0)
            Dim topPos As Point = New Point(Me.Left, Me.Top)
            'Set up blending options
            Dim blend As api1.BLENDFUNCTION = New api1.BLENDFUNCTION
            blend.BlendOp = api1.AC_SRC_OVER
            blend.BlendFlags = 0
            blend.SourceConstantAlpha = 255
            blend.AlphaFormat = api1.AC_SRC_ALPHA
            api1.UpdateLayeredWindow(Me.Handle, screenDc, topPos, size, memDc, pointSource, 0, blend, api1.ULW_ALPHA)
            'Clean-up
            bmp.Dispose()
            api1.ReleaseDC(IntPtr.Zero, screenDc)
            If (hBitmap <> IntPtr.Zero) Then
                api1.SelectObject(memDc, oldBitmap)
                api1.DeleteObject(hBitmap)
            End If
            api1.DeleteDC(memDc)
        Catch


        End Try
    End Sub

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = (cp.ExStyle Or 524288)
            Return cp
        End Get
    End Property
End Class

Class api1

    Public Const AC_SRC_OVER As Byte = 0
    Public Const AC_SRC_ALPHA As Byte = 1
    Public Const ULW_ALPHA As Int32 = 2

    <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    Public Structure BLENDFUNCTION
        Public BlendOp As Byte
        Public BlendFlags As Byte
        Public SourceConstantAlpha As Byte
        Public AlphaFormat As Byte
    End Structure

    Public Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdcDst As IntPtr, ByRef pptDst As Point, ByRef psize As Size, ByVal hdcSrc As IntPtr, ByRef pprSrc As Point, ByVal crKey As Int32, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Int32) As Boolean
    Public Declare Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
    Public Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As IntPtr) As IntPtr
    Public Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
    Public Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Boolean
    Public Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As IntPtr, ByVal hObject As IntPtr) As IntPtr
    Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As IntPtr) As Boolean
End Class

Open in new window

0
Comment
Question by:altariamx2003
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40433830
I suspect that your issue is here:

The only drawback is the UpdateLayeredWindow API call (which is the one that renders the image) makes normal controls not appear. There is no way around this, except to draw the image with other methods or move to newer technologies such as WPF.
0
 

Author Comment

by:altariamx2003
ID: 40434927
mmmmm  

ok thanks for you help
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB: Convert 2 dates to specific format 24 48
Help with preventing downloading a zip file 10 37
Sort GridView by ID Descending 1 13
vb.net and creating a class 5 17
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question