Solved

Splash Screen - stay on top

Posted on 2001-06-07
10
675 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 142

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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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