|
Creating a preview option for your Win95 screen saver
If you've tried the Windows 95 screen saver setup, you will have noticed the preview option, where the screen saver is shown inside a small screen. Here's the code to do the same.
Author: Jeff Hackl
Attribute VB_Name = "Module1"
Option Explicit
Dim StartMode$
'Declare constants for the BitBlt function
Public Const BLACKNESS = &H42&
Public Const SRCCOPY = &HCC0020
' Place the following declares each on one line.
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As _
Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal _
dwRop As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc _
As Long) As Long
Public Sub Main()
'Get the command line parameter.
StartMode$ = Left$(Command$, 2)
'Case the command line parameter.
Select Case StartMode$
Case "/s", "/S"
'Place code to start saver here.
Case "/c", "/C"
'Place code to configure saver here.
Case "/p", "/P"
'Exit if app is already running.
If App.PrevInstance Then End
'Call procedure to bitblt screen to preview box.
GrabScreen
End Select
End Sub
Public Sub GrabScreen()
Dim Temp%, PrevHWND%, PrevDC, ScreenhWnd, ScreenDC, I
' Get hWnd to the preview window from the command line.
PrevHWND% = CInt(Right$(Command$, Len(Command) - 3))
' Get hDc to the preview window.
PrevDC = GetDC(CInt(Right$(Command$, Len(Command) - 3)))
' Get hWnd to Desktop
ScreenhWnd = GetDesktopWindow()
' Get hDC of Desktop
ScreenDC = GetDC(ScreenhWnd)
' Not sure why but BitBlt will not work without this line.
DoEvents
' BitBlt a portion of the desktop to the preview window.
Temp = BitBlt(PrevDC, 0, 0, 152, 112, ScreenDC, 0, 0, SRCCOPY)
' Release DC for Screen
Temp = ReleaseDC(ScreenhWnd, ScreenDC)
' Note: the preview window is 152 x 112 pixels
' Draw vertical lines using bitblt
For I = 1 To 8
Temp = BitBlt(PrevDC, (I * 19) - 1, 0, 1, 112, 0, 0, 0, BLACKNESS)
Next I
' Draw horizontal lines using bitblt
For I = 1 To 4
Temp = BitBlt(PrevDC, 0, (I * 28) - 1, 152, 1, 0, 0, 0, BLACKNESS)
Next I
' Release DC for Preview Window when you are done with it.
Temp = ReleaseDC(PrevHWND, PrevDC)
' If you are running a loop use the IsWindowVisible function
' to detect when the preview window is closed.
' If IsWindowVisible(PrevHWND%) = 0 Then
End
End Sub
Save the following as SAMPLE.VBP
Module=Module1; Sample.bas ProjWinSize=237,390,248,215 ProjWinShow=2 HelpFile="" Title="SCRNSAVE Sample" ExeName32="Sample.scr" Name="Project1" HelpContextID="0" StartMode=0 VersionCompatible32="0" MajorVer=1 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 |
||
|
Editor: Jeff Hackl Last update: 2025-10-26 Copyright 1995-2025 VBI |