Solved

Splash Screen - stay on top

Posted on 2001-06-07
10
679 Views
Last Modified: 2010-08-05
Hi,

I have a splash screen in my app. Right now it is loaded in sub main before the main form loads. I am using windows api to make the splash screen stay on top of all applications. Unfortunately sometimes my application takes a long time to load, so having the form stay on top of everything is annoying. How can I make it so that it will only stay on top of my application, while still having it start up before my app.

Thanks,

Zaphod.
0
Comment
Question by:Z_Beeblebrox
10 Comments
 
LVL 2

Expert Comment

by:kiprimshot
ID: 6164067
Why not just load your app in the background...dont show it until all is loaded
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6164093
Actually, i have generally this type of code:

private gfrmMain as frmMain


Sub Main()
  dim frmSplash as frmSplash
 
  set gfrmMain = new frmMain
  set frmSplash = new frmSplash

  gfrmMain.Visible = true
  frmSplash.Show vbModeless, gfrmMain
  doevents

  ...
  continue with the startup of app
  ...


  frmSplash.hide  
  unload frmSplash
  set frmSplash = nothing

End Sub



This needs that there is NO code in the Form_Load() event of frmMain , and the initial size should be quite small.

Cheers
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6164103
Sub Timer1_Timer ()  
Unload Form1
Load Form2

Form2.Show  
End Sub'The above code tells Visual Basic that
'     after the Timer control waits for the ti
'     me specified by the Interval property, i
'     t should unload Form1 (your splash scree
'     n) and then load and display Form2 (whic
'     h contains your 'program's first screen)
'     .


Sub Image1_Click ()  
Timer1.Enabled = False
Unload Form1  
Load Form2
Form2.Show  
End Sub'Experiment with creating splash screens


 

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 6164861
>so having the form stay on top of everything is annoying.

Good catch!  I will never understand why *all* samples put Splash 'Always_On_Top'.

>How can I make it so that it will only stay on top of my application

Show it the 'normal' way:
    frmSplash.Show
and then show your main form *behind* it:
    ' use second parameter in SetWindowPos - insert main form AFTER frmSplash
    SetWindowPos frmMain.hwnd, frmSplash.hwnd, 0, 0, 0, 0, SWP_SHOWWINDOW Or _
        SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE

I'll post a little sample...
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6165032
ameba, your answer seems closest to what I want, but it doesn't seem to work. Regardless of what I do, the splash screen comes up behind the main form.

Any ideas?

Zaphod.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6165088
' frmMain ------------------------------------------------------------
Option Explicit

Private Sub Form_Load()
    Sleep 3000
End Sub

' frmSplash borderstyle=None, caption="" -----------------------------
Option Explicit

Private Sub Form_Load()
    BackColor = vbInfoBackground  'background color of tooltips
End Sub

' module1  -----------------------------------------------------------
Option Explicit
' API declarations
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub main()
    frmSplash.Show
    DoEvents
   
    Load frmMain ' this
    DoEvents
    If GetActiveWindow = frmSplash.hwnd Then
        ' frmsplash is on top
        ' temporary put frmSplash TOPMOST, just to allow frmMain to show with focus
        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
        ' frmsplash is not on top
        ' use second parameter in SetWindowPos - insert mainform AFTER frmSplash, without focus
        SetWindowPos frmMain.hwnd, frmSplash.hwnd, 0, 0, 0, 0, SWP_SHOWWINDOW Or _
                SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE
    End If
    DoEvents
   
    Sleep 2000
    DoEvents
    Sleep 2000

    Unload frmSplash
    Set frmSplash = Nothing
End Sub
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6165127
Hi,

Heres what I did:

Put this into a module, then just before showing the main form (inside the main form load event) call set owner. It works quite well and is not too complicated. ameba, since you inspired me, I will give you the points.

Zaphod.

Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Private Const GWL_HWNDPARENT = (-8)
Public lngSplashHWND As Long

Public Function SetOwner(ByVal HwndtoUse, ByVal HwndofOwner) As Long
    SetOwner = SetWindowLong(HwndtoUse, GWL_HWNDPARENT, HwndofOwner)
End Function
0
 
LVL 15

Expert Comment

by:ameba
ID: 6165159
>ameba, since you inspired me, I will give you the points.

:-) Thanks!

or maybe set owner without API

' in frmMain
Private Sub Form_Load()
    frmSplash.Show vbModeless, Me   ' set owner form
    frmSplash.Refresh
    Show
    DoEvents
   
    Sleep 3000 ' do something
   
    Unload frmSplash
End Sub
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6165456
The reason I do it with api is that i show the splash screen before I start loading the main form, and then later on I set its owner.

Zaphod.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6165591
Yes, I understand it, it's very good method.
I just wanted to add something useful if somebody buys this PAQ.  ;-)

I'm glad to meet someone who cares so much for the users, and notices those little details.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 64
Run code from text file in vb 1 74
VB6 ListBox Question 4 50
VBA: copy range dynamically based on config sheet v2 3 50
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 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