Setting Up VB
There are a few housekeeping items to get your Visual Basic environment set up appropriately for a screen saver project. The steps below will take you through this process.
The first thing to do is to create an EXE project. This is done by choosing Standard Exe from the New Project dialog in the Visual Basic IDE (see Figure 2).
Figure 2 The New Project dialog box.
Next you need to make a reference to the DirectX 8 VB type library. To do this, choose Project, References from within VB. The DirectX type library will be listed as DirectX 8 for Visual Basic Type Library (see Figure 3). Select this library and choose OK.
Figure 3 The Project References dialog box.
You need to change the settings in the property window so that Windows knows this is a screen saver. Open the Project Properties window. Here you need to choose the Make tab and change the title to SCRNSAVE:Snowman (see Figure 4). This will make sure that Windows correctly recognizes your screen saver.
Figure 4 Changing the title in the Project Properties dialog box.
Windows will make a call to the Sub Main() function of your program when the screen saver is activated. Therefore you need to add a module to your program to handle this call. To do this, choose Add Module from the Project menu and choose the default module.
Through your Sub Main(), Windows passes information to your screen saver so that it can tell you that the user wants to launch the screen saver, change the password, configure, or stop the screen saver. The code for how this is done in VB is listed below. Copy this code into your Module1.
Sub Main() On Error Resume Next Dim strCmdLine As String strCmdLine = Left(Command, 2) Select Case strCmdLine Case "/a" ' password change Case "/c" ' configure button pressed Call Load(frmConfigure) frmConfigure.Show Case "/p" ' end screen saver Unload frmMain Case "/s" ' run the screen saver Call Load(frmMain) frmMain.Show Case Else ' This is in here in case you want to test the ' screen saver outside of loading it. Call Load(frmMain) frmMain.Show End Select End Sub
You also need to set the Sub Main() routine as your starting point. To do this, select Project, Snowman Properties. In the Project Properties dialog, change the Startup Option to Sub Main (see Figure 5).
Figure 5 Changing the startup options.
Part 2 of this series describes how to write the DirectX code to animate the screen saver.