Solved

splash screen using a transparent png with vb.net

Posted on 2014-11-10
2
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

763 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