Adding Visual Effect with Splash Screens

Creating a "Virus" to Prevent Unauthorized Use of Your Computer

Creating a Form with a Thin Title Bar

 

 

 

Adding Visual Effect with Splash Screens

Source: MSDN 98

Abstract

You can make your Visual Basic® applications more attractive and professional looking if you include a splash screen. Splash screens are simply forms that are displayed as soon as your application program is executed.

Splash screens are used to display important information (such as copyright notices) to users when the application is first executed. Sometimes, splash screens are presented to users while the application is performing time-consuming operations.

Creating Splash Screens

To create a splash screen for an application in Visual Basic®, you add text boxes, pictures, or any other graphic element to your form. After the form has been created, you add it to your existing project file. To display the splash screen, you use the Visual Basic Show command. While the splash screen is being displayed, you can perform other operations in your program.

Example Program

The example application described below displays a splash screen to the user for a short period of time. After the splash screen is displayed, the program's main form is displayed. Click the Exit command button to terminate the application.

  1. Create a new project in Visual Basic. Form1 is created by default. This form will be your splash screen. Set its Caption property to "Splash Screen" and its Name property to "Splash".

  2. Add a Picture Box control to Form1. Picture1 is created by default. Set its Picture property to a bitmap, such as that provided in C:\VB\BITMAPS\ASSORTED\HAPPY.BMP.

  3. Add a Text Box control to Form1. Text1 is created by default. Set its Text property to "Splash Screen Demo". Set its BorderStyle property to 1-Fixed Single.

  4. Save the form under the filename SPLASH.FRM.

  5. Create a new project in Visual Basic. Form1 is created by default. Set its Caption property to "VB Splash Screen Demo".

  6. Add a Command Button control to Form1. Command1 is created by default. Set its Caption property to "Exit".

  7. Add the following code to the Click event for Command1:
    Sub Command1_Click()
        End
    End Sub
    
  8. Next, add the SPLASH.FRM form created in steps 1 through 4 to your project by selecting Add File from the Visual Basic menu.

  9. Create a New Module file and name the module SPLASH.BAS.

  10. Add the following code to the SPLASH.BAS module:
    Sub Main()
        Dim X As Long, P As Integer
        Splash.Show
        For X = 1 To 100000
            P = DoEvents()
        Next X
        Beep
        Unload Splash
        Load Form1
        Form1.Show
    End Sub
    
  11. Set the Startup Form to Sub Main. Save the entire Visual Basic project as SPLASH.VBP

 

Creating a "Virus" to Prevent Unauthorized Use of Your Computer

Source: MSDN

Abstract

This article explains how you can design an application in Visual Basic® that acts like a virus. You can use this program to prevent unauthorized users from using your system for more than 10 minutes.

A 10-Minute Virus Stops Others from Using Your Computer

If you are working in an office situation where other users have access to your computer system, you may want to develop a Visual Basic® application that can prevent unauthorized use of your computer.

The MSDNBUG.EXE virus program interrupts the currently running Windows®-based application after the computer has been running for 10 minutes. The program immediately displays a stay-on-top form that remains on the screen until the virus program is terminated by holding down the ALT key and typing 169 on the numeric keypad while the focus is on the Picture Box control. In addition, once the virus program has been actuated, the Timer control is used to display a message about not removing the diskette in drive B. This message box is displayed approximately once every second. Again, the user cannot remove the diskette in drive B or return to the previously running Windows-based application—the only alternative is to reboot the computer system, and the user is warned not to do this to prevent further "damage" to the hard drive's contents.

Example Program

The program below is a sample virus application written in Visual Basic. Because the program is added to the StartUp group on the Windows desktop, it will be executed each time the computer is turned on. After the user has been working on the computer for 10 minutes, the virus will interrupt the currently running application and display its screen. If the user attempts to remove a diskette from drive B, the program will also display a message box telling the user not to remove the diskette because it has a hidden file that is needed to restore the computer to its normal condition. The program can be terminated only by holding down the ALT key and typing 169 on the numeric keypad.

  1. Create a new project in Visual Basic. Form1 is created by default. Set the following properties for Form1:

    Caption: WARNING: FATAL VIRUS DETECTED
    ClipControls: False
    ControlBox: False
    KeyPreview: True
    MaxButton: False
    MinButton: False
    Visible: False

  2. Add the following Dim, Constant, and Declare statements to the General Declarations section of Form1 (note that the Declare statement must be typed as a single line of code):
    Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal 
       hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal CX 
       As Integer, ByVal CY As Integer, ByVal wFlags As Integer) As Integer
    
    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const SWP_NOACTIVATE = &H10
    Dim FunLoad As Integer
    Dim Hwnd_Topmost As Integer
    Dim Wp As Integer
    Dim NumTimerEvents As Integer
    
  3. Add the following code to the Form_Load event for Form1 (note that the Wp line must be typed as a single line of code):
    Sub Form_Load()
      Hwnd_Topmost = -1
      Wp = SetWindowPos(Form1.hWnd, Hwnd_Topmost, 0, 0, 0, 0, SWP_NOSIZE + 
        SWP_NOMOVE + SWP_NOACTIVATE)
      Form1.Hide
      Timer1.Interval = 65535
      Timer1.Enabled = True
      NumTimerEvents = 0
    End Sub
    
  4. Add the following code to the KeyPress event for Form1:
    Sub Form_KeyPress(KeyAscii As Integer)
      If KeyAscii = 3 Then FunLoad = True
    End Sub
    
  5. Add the following code to the Unload event for Form1:
    Sub Form_Unload(cancel As Integer)
      If Not FunLoad Then cancel = True: End
    End Sub
    
  6. Add a Label control to Form1. Label1 is created by default. Set the following properties for Label1:

    AutoSize: False
    BorderStyle: 0-None
    Caption: WARNING: The diskette in drive B has the MSDN virus.

  7. Add a second Label control to Form1. Label2 is created by default. Set the following properties for Label2:

    BorderStyle: 0-None
    AutoSize: False
    Caption: This virus has corrupted the directory of all files on the hard drive of this computer. This virus copies the original information to a hidden file on the diskette that is required for recovery of the hard drive. DO NOT TURN OFF THE COMPUTER. Please contact Customer Support at (360) 297-4717 for instructions (Monday to Friday, 8 a.m. to 4 p.m. Eastern time).

  8. Add a Picture Box control to Form1. Picture1 is created by default. Set the following properties for Picture1:

    BorderStyle: 1-Fixed Single
    Picture: C:\VB\METAFILE\BUSINESS\COMPUTERS.WMF

  9. Add the following code to the KeyPress event for Picture1 (note that the Wp line must be typed as a single line of code):
    Sub Picture1_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 169 Then Exit Sub
      Hwnd_Topmost = -2
      Wp = SetWindowPos(Form1.hWnd, Hwnd_Topmost, 0, 0, 0, 0, SWP_NOSIZE + 
           SWP_NOMOVE + SWP_NOACTIVATE)
      End
    End Sub
    
  10. Add a Timer control to Form1. Timer1 is created by default. Set the following properties for Timer1:

    Enabled: True
    Interval: 1000

  11. Add the following code to the Timer event for Timer1 (please note that the MsgBox line must be typed as a single line of code):
    Sub Timer1_Timer()
      Const Max_Intervals = 5     '5 minutes
      NumTimerEvents = NumTimerEvents + 1
      If NumTimerEvents >= Max_Intervals Then
    
    On Error Resume Next
    'If the diskette has been removed, the timer is reset 
    'to display the error message box once every second.
    If Len(Dir("B:*.*")) = 0 Then
      If Visible Then
          Timer1.Interval = 1000
          MsgBox "The virus-infected diskette has been removed from the PC -- 
            recovery may not be possible.", 16, "MSDN Virus"
      End If
    Else
      Visible = True
      WindowState = 2
    
    End If
    On Error GoTo 0
    End If
    
    End Sub
    
  12. Create an executable program file by selecting File/Make EXE File from the Visual Basic menu. Save the program file as MSDNBUG.EXE.

  13. Add the MSDNBUG.EXE program to the StartUp group on your Windows desktop.

 

Creating a Form with a Thin Title Bar

June 5, 1995

Abstract

Many Microsoft® Windows®-based applications include a Toolbox control. A toolbox is a group of icons that the user can click to perform various operations within a running application. These toolbox windows usually display a very small, thin title bar instead of the normal-sized title bar. This article explains how you can create forms with thin title bars in your Visual Basic® applications.

Using SendMessage and GetCursorPos to Create Title Bars

You can design a form that contains a thin title bar. This is most often used in Toolbox controls from which the user can click on an icon to perform a  program operation.

In the example program below, we use a Label control, sized to fit at the top of our form. This control, which will become the thin title bar, responds to both the Click and MouseDown events. These two events allow the user to click on the Label control (that is, the thin title bar) and drag the entire form to a new location on the screen. This gives our Microsoft® Visual Basic® application the same functionality as a toolbox window.

To enable our user to drag the form to a new location on the screen, we need to determine the cursor's current X and Y coordinates on the screen. You can use the Microsoft® Windows® application programming interface (API) GetCursorPos function to retrieve the cursor's current location.

To call the GetCursorPos function, you must first add its Declare statement to the General Declarations section of your Visual Basic application. Following is the declaration for the GetCursorPos function:

Private Declare Sub GetCursorPos Lib "User" (lpPoint As POINTAPI)

The GetCursorPos function requires only one argument—a POINTAPI structure. This structure will hold the cursor's current position, which is reported in screen coordinate values.

The cursor's horizontal position is stored in the X variable; the cursor's vertical position is stored in the Y variable within the POINTAPI structure:

Type POINTAPI
    X As Integer
    Y As Integer
End Type

After the cursor's position has been retrieved, we issue the LSet statement to convert the X and Y values to values that can be understood by the SendMessage function. In other words, LSet converts the X and Y integers to a single long value.

Next, we issue two SendMessage commands to Windows. The first SendMessage statement tells Windows that, because a MouseDown event has just occurred, it needs an equivalent MouseUp event. The second SendMessage statement tells Windows that the user has clicked the title bar. Windows then processes our thin title bar's Click and MouseDown events as it would for a normal window.

Example Program

This program shows how to create a form with a small title bar.

  1. Create a new project in Visual Basic. Form1 is created by default.

  2. Set the following properties for Form1:
ClipControls 0  'False
ControlBox 0  'False
MaxButton 0  'False
MinButton 0  'False

  1. Add the following Constant and Declare statements to the General Declarations section of Form1 (note that the Declare statements must be typed as single lines of text):
    Private Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal
       wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Any) As Long
    Private Declare Sub GetCursorPos Lib "User" (lpPoint As POINTAPI)
    Const WM_LBUTTONUP = &H202
    Const WM_SYSCOMMAND = &H112
    Const MOUSE_MOVE = &HF012
    
  2. Add a Label control to Form1. Label1 is created by default. Set its Caption property to "Thin Title Bar".

    Note: For this example program, change the size of Form1 so that it resembles the size and shape of a Toolbox window. Next, position the Label control at the top of the form and adjust its size so that it isthe same size as a thin title bar.

  3. Add the following code to the Click event for Label1:
    Private Sub Label1_Click()
        Dim mpos As POINTAPI
        Dim P As ConvertPOINTAPI
        Dim Ret As Integer
        
        Call GetCursorPos(mpos)
        LSet P = mpos
        Ret = SendMessage(Me.hWnd, WM_LBUTTONUP, 0, P.XY)
        Ret = SendMessage(Me.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, P.XY)
        
    End Sub
    
  4. Add the following code to the MouseDown event for Label1 (note that the first two lines must be typed as a single line of code):
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer,
     X As Single, Y As Single)
        Dim mpos As POINTAPI
        Dim P As ConvertPOINTAPI
        Dim Ret As Integer
        
        Call GetCursorPos(mpos)
        LSet P = mpos
        Ret = SendMessage(Me.hWnd, WM_LBUTTONUP, 0, P.XY)
        Ret = SendMessage(Me.hWnd, WM_SYSCOMMAND, MOUSE_MOVE, P.XY)
    End Sub
    
  5. From the Insert menu, select Module. Module1.Bas is created by default.

  6. Add the following type declarations to Module1.Bas:
    Type POINTAPI
        X As Integer
        Y As Integer
    End Type
    Type ConvertPOINTAPI
        XY As Long
    End Type
    

Run the example program by pressing F5. Form1 should be displayed on the screen with the thin title bar appearing at the top of the form. You can drag the form by clicking on the title bar, just as you would do with any other window that has a title bar.