Solved

Splash Screen - stay on top

Posted on 2001-06-07
10
678 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

832 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