Solved

splash screen using a transparent png with vb.net

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

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
mmmmm  

ok thanks for you help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

12 Experts available now in Live!

Get 1:1 Help Now