What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleCreate a splash screen
DescriptionThis example shows how to create a splash screen in Visual Basic 6.
Keywordssplash screen
CategoriesControls, Software Engineering
When the program starts, it disables the program's main form and displays it. It then displays the splash screen and does whatever it needs to get started: loads Registry settings, loads data, etc. This example just loops to waste a little time.

When it finishes getting ready to start, the main form calls the splash form's ReadyToWork method.

Private Sub Form_Load()
Dim i As Integer

    ' Disable this form. The splash screen will
    ' reenable the form when it unloads.
    Enabled = False
    ' Make the main form visible.
    ' Display the splash screen.
    ' Do stuff to get the program ready, read
    ' values from the registry, open databases, etc.
    For i = 1 To 10000
        ' Just waste a little time.
    Next i
    ' Let the splash screen know we are ready
    ' to begin work.
End Sub
The splash form contains a timer. When the form loads, it enables the timer, centers the form, and makes the form topmost.

When the timer fires, the program sets the TimerExpired variable to True and disables the timer. If the ReadyToUnload variable is also True, the program calls subroutine HideSplash to unload the splash screen.

When the main program calls the ReadyToWork subroutine, the program sets ReadyToUnload to True. If TimerExpired is also True, the program calls subroutine HideSplash to unload the splash screen.

When both TimerExpired and ReadyToUnload are True, subroutine HideSplash re-enables the main form and closes the splash form.

Private ReadyToUnload As Boolean
Private TimerExpired As Boolean

Public Sub ShowSplash()
    ' The minimum amount of time the splash screen
    ' will be visible.
    SplashTimer.Interval = 3000
    ' Center the form.
    Left = (Screen.Width - Width) / 2
    Top = (Screen.Height - Height) / 2
    ' Make this a topmost window.
    SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
    ' Display the form.
End Sub

' The minimum time has expired.
Private Sub SplashTimer_Timer()
    TimerExpired = True
    SplashTimer.Enabled = False
    If ReadyToUnload Then HideSplash
End Sub

' The main program is ready to start work.
Public Sub ReadyToWork()
    ReadyToUnload = True
    If TimerExpired Then HideSplash
End Sub

' The minimum amount of time has expired and the
' program is ready to begin work.
Private Sub HideSplash()
    ' Reenable the main program.
    Form1.Enabled = True

    ' Remove the splash screen.
    Unload Me
End Sub
Fancier splash screens including irregularly shaped splash screens, elliptical splash screens, etc. are described in my book Advanced Visual Basic Techniques.
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.