home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


If the main application sets AboutDialog to true, the form will be used as an about dialog. In that case, AboutDialog disables the splash screen timer. It makes the OK button visible and sets the height of the form to be large enough to display the button. Finally, it sets the form’s Caption property. This is important because it makes the form display a title bar. The user can grab the title bar with the mouse and drag it to other parts of the screen.

If the main application sets AboutDialog to false, the form will be used as a splash screen. In that case, AboutDialog enables the splash screen timer. In design mode, the timer’s Interval property should be set to indicate the minimum length of time the splash screen will be displayed. This value should not be greater than two or three seconds (2000 or 3000 milliseconds), or the user may be annoyed.

AboutDialog next makes the OK button invisible and sets the height of the form to a reasonable value given that the OK button is hidden. Finally, it blanks the form’s Caption property so that the form has no title bar. The user does not need to be able to move the splash screen because it will be displayed for only a short time.


FIGURE 2.9  A form used for a splash screen and an about dialog.

Property Let AboutDialog(value As Boolean)
Const MARGIN = 240

    If value Then
        SplashTimer.Enabled = False
        CmdOk.Visible = True
        Height = CmdOk.Top + _
            CmdOk.Height + MARGIN
        Caption = “About ExpenseReporter”
    Else
        SplashTimer.Enabled = True
        CmdOk.Visible = False
        Height = RightsLabel.Top + _
            RightsLabel.Height + MARGIN
        Caption = “”
    End If
End Property

When the form is displayed as an about dialog, it handles the OK button in a simple way. The OK button’s Click event handler simply unloads the form.

Private Sub CmdOk_Click()
    Unload Me
End Sub

When the form is displayed as a splash screen, unloading it is a bit more complicated. The splash screen should unload itself whenever the minimum amount of time has expired or when the application has finished loading and is ready for work, whichever comes second. To keep track of both of these events, the form defines two Boolean variables in its declarations section.

Dim timer_expired As Boolean
Dim ready_to_unload As Boolean

The splash screen’s Load event procedure sets both of these variables to false, indicating that the timer has not yet expired and that the application is not yet ready for the splash screen to unload. The Load event handler also centers the form on the user’s computer and ensures that no other screen can be moved on top of it. It performs this last feat using the SetWindowPos API function.

Private Sub Form_Load()
Dim status As Long

    ‘ Initially the form has just been presented
    ‘ and is not ready for unloading.
    timer_expired = False
    ready_to_unload = False

    ‘ Center the form.
    Left = (Screen.Width - Width) / 2
    Top = (Screen.Height - Height) / 2

    ‘ Make this window stay on top of others.
    status = SetWindowPos(hWnd, HWND_TOPMOST, _
        0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
End Sub

The form provides a property let procedure, ReadyToUnload. The main program calls this procedure when it has finished initialization and it is ready to begin work. ReadyToUnload sets the value of the form’s ready_to_unload variable to true. If the timer_expired variable also has the value true at that time, the procedure unloads the splash screen. ReadyToUnload also enables the application’s main form and sends the input focus to that form.

Property Let ReadyToUnload(value As Boolean)
    ready_to_unload = value

    If timer_expired Then
        Unload Me
        ExpenseForm.Enabled = True
        ExpenseForm.SetFocus
    End If
End Property

The timer’s Timer event handler is similar. It sets timer_expired to true and unloads the form if ready_to_unload is also true.

Private Sub SplashTimer_Timer()
    timer_expired = True
    SplashTimer.Enabled = False

    If ready_to_unload Then
        Unload Me
        ExpenseForm.Enabled = True
        ExpenseForm.SetFocus
    End If
End Sub

Now the main application can use the form as both a splash screen and an about dialog. The main application’s Load event handler presents it as a splash screen as shown in the following code. Notice that the program disables the application’s main form before presenting the splash screen. This prevents the user from interacting with the main application while the splash screen is visible. The splash screen’s ReadyToUnload and SplashTimer_Timer routines reenable the main form before unloading the splash screen.

Private Sub Form_Load()
    ‘ Disable the form. The splash screen will
    ‘ enable the form when it unloads.
    Enabled = False

    ‘ Display the splash screen.
    Splash.AboutDialog = False
    Splash.Show vbModeless

    ‘ Force the splash screen to display itself.
    Splash.Refresh

    ‘ Load data, arrange controls, and perform other initialization.
    :

    ‘ Tell the splash screen we have finished initialization.
    Splash.ReadyToUnload = True
End Sub

It is even easier to use the form as an about dialog. The form is displayed modally so the user must close the dialog before returning to the main application. The following code shows how the About command in ExpenseReporter’s Help menu displays the about dialog.

Private Sub mnuHelpAbout_Click()
    Splash.AboutDialog = True
    Splash.Show vbModal
End Sub

Summary

Chapters 1 and 2 explain a collection of application programming techniques that give an application a polished look. Most users have seen advanced features such as scrolling areas, recent file lists, and print preview in commercial applications. Adding these familiar features to an application makes users comfortable and makes the application appear sophisticated.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.