by Stephan Kirchmaier (8 Submissions)
Category: DirectX
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (7 Votes)
It's my first DirectX Project. Please say what you think of it!
Inputs
You must link "DirectX7 for Visual Basic Type Library" to your Project.
Assumes
The ScreenSaver ends by clicking on the screen.
Option Explicit
Private DX7 As DirectX7
Private DXD As DirectDraw7
Private DXDS As DirectDrawSurface7
Private DXSD As DDSURFACEDESC2
Private Sub Form_Load()
Dim i As Long, j As Long
frmMain.Show
'Create a DirectX7-Object and a DirectDraw-Object
Set DX7 = New DirectX7
Set DXD = DX7.DirectDrawCreate("")
With DXSD
.lFlags = DDSD_CAPS
.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
End With
'Fullscreen and set the resolution to 640 X 480
DXD.SetCooperativeLevel frmMain.hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
DXD.SetDisplayMode 640, 480, 16, 0, DDSDM_DEFAULT
'Create the Surface using the Surfacedescription DXSD
Set DXDS = DXD.CreateSurface(DXSD)
i = 0
Do Until DoEvents()
For j = 0 To ScaleWidth Step 50
'Set the Linecolor
DXDS.SetForeColor i
'Draw the line
DXDS.DrawLine Rnd * Screen.Width, Rnd * Screen.Height, j, 0
i = i + 1
'Change the color
If i = 65536 Then
i = 0
End If
Next j
Loop
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call endp
End Sub
Private Sub endp()
'Clean up things
DXD.RestoreDisplayMode
Set DX7 = Nothing
Set DXD = Nothing
Set DXDS = Nothing
End
End Sub