jakemail
asked on
Load Splash Screen
What code do I use to make my splash screen functional. ie. make it visible until the rest of the application is loaded and ready to go then hide it. This is probably simple but I'm not sure how to do it. Any help would be appreciated.
This will display a splash screen for as long as it takes to load frmMain. Add a delay if you want to show the screen longer.
'~~~~Splash Code~~~~
Private Sub Form_Load()
Show
Refresh
Load frmMain
Hide
frmMain.Show
Unload Me
End Sub
'~~~~Splash Code~~~~
Private Sub Form_Load()
Show
Refresh
Load frmMain
Hide
frmMain.Show
Unload Me
End Sub
Splash Form:
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static timertime As Integer
timertime = timertime + 1
If timertime = 5 Then
Form2.Show
Unload Me
Set Form1 = Nothing
End If
End Sub
Form2:
Private Sub Form_Load()
Form1.Hide
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static timertime As Integer
timertime = timertime + 1
If timertime = 5 Then
Form2.Show
Unload Me
Set Form1 = Nothing
End If
End Sub
Form2:
Private Sub Form_Load()
Form1.Hide
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The MS recommendation is
Private Sub Main()
' Show the splash screen.
frmSplash.Show
' Add your startup procedures here.
…
' Show the main form and unload the splash screen.
frmMain.Show
Unload frmSplash
End Sub
Private Sub Main()
' Show the splash screen.
frmSplash.Show
' Add your startup procedures here.
…
' Show the main form and unload the splash screen.
frmMain.Show
Unload frmSplash
End Sub
MS solution is good, but sometimes you'll have both the splash and the main up. Even if for a short time. They can collide with one another on slower machines and give a graphics flicker.
I found this is the best way (smooth, user friendly multitasking):
Public Sub Main()
frmSplash.Show
DoEvents
Load frmMain ' open db, ...
DoEvents
If GetActiveWindow = frmSplash.hWnd Then
SetWindowPos frmSplash.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
frmMain.Show
SetWindowPos frmSplash.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
Else
SetWindowPos frmMain.hWnd, frmSplash.hWnd, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
End If
DoEvents
If Len(Command) Then
' do something
End If
Unload frmSplash
Set frmSplash = Nothing
End Sub
Public Sub Main()
frmSplash.Show
DoEvents
Load frmMain ' open db, ...
DoEvents
If GetActiveWindow = frmSplash.hWnd Then
SetWindowPos frmSplash.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
frmMain.Show
SetWindowPos frmSplash.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
Else
SetWindowPos frmMain.hWnd, frmSplash.hWnd, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOSIZE Or SWP_NOMOVE
End If
DoEvents
If Len(Command) Then
' do something
End If
Unload frmSplash
Set frmSplash = Nothing
End Sub
When the timer is triggered it with hide the splash screen
The code I use goes something like this.
--------------------------
private sub form_load()
Splash1.show
Timer1.enabled = true
end sub
--------------------------
private sub timer1_()
splash1.hide
timer1.enabled = false
end sub
--------------------------
I am not sure whether this is the right way but it works.
Hope this helps.