Solved

splash screen using a transparent png with vb.net

Posted on 2014-11-10
2
277 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now