Current location - Health Preservation Learning Network - Slimming men and women - How to make your own screensaver?
How to make your own screensaver?
It is very easy to make a screen saver with Visual Basic. This paper will introduce the method of making screen saver in detail.

-1. Basic programming ideas

As we all know, screen savers use transformed colors or graphics to prevent unchanging screen pixels from being damaged. Therefore, the screen saver is a program that displays constantly changing or moving graphics, and can be terminated when the mouse moves or presses a key.

-1. Compile the screen saver graphics.

-2. Hide the mouse

-We can hide the mouse with the function of ShowCursor Windows API.

-3. Detect mouse and key behavior.

-Detect the above behavior to exit the screen saver.

-4.Windows calls the parameter command of the screen saver.

-/a Click the Change Password button in the Display Properties dialog box.

-/p Whenever the Screen Saver tab in the Display Properties dialog box is selected, a preview effect will be displayed in the dialog box.

-/c Click the Settings button in the Display Properties dialog box.

-/s Click the Preview button in the Display Properties dialog box, or the system will call the screen saver normally.

-5. Compile the screen saver

-In fact, any VB application can run as a screensaver, but it needs to be compiled into a screensaver in order to be called by Windows 95. First, enter the VB5 programming environment, select the /File/Make project menu item after programming, and then change the suffix EXE to SCR in the file name text box. Finally, click the OK button to copy the generated SCR file to the Windows directory, thus completing the creation of the screensaver.

-two. example

-Here's an example to illustrate how to make a screensaver in detail.

Option explicit

Dimquit flag as boolean' declares the termination program flag variable.

Dim left side

Declare an API function that hides or shows the mouse.

Private declaration function ShowCursor Lib "user32 "

(ByVal bShow As Long) as long as

Detect mouse clicks or movements.

Private Sub-Form _Click ()

quitflag = True

End joint

Private sub-form _MouseMove (button is an integer,

Shift to integer, x is single precision, y is single precision)

Static xlast

Adjust xnow to a single

Dim ynow is single

xnow = X

ynow = Y

If xlast = 0 and ylast = 0, then

xlast = xnow

ylast = ynow

outlet connection

If ... it will be over.

If xnow & lt& gtxlast or ynow & lt& gt, then go there.

quitflag = True

If ... it will be over.

End joint

"Test key"

Private subform _ keyword down (keyword is an integer,

As an integer shift)

quitflag = True

End joint

Private Sub-Form _Load ()

Dim X As Long

lleft = 0

The starting x coordinate of horizontally scrolling text.

If App。 Then PrevInstance = True

Use the PrevInstance property of the APP object.

Unload me.

Prevents two instances of the screen saver from running at the same time.

outlet connection

If ... it will be over.

select Case Ucase $(Left $(Command $,2))

Load command line parameters

Click the case "/s" in the Show Properties dialog box.

The preview button or screen saver is usually called by the system.

show

Show form in full screen 1 form

Irregular

Initialize the random number generator.

X = ShowCursor(False)

Hide mouse

BackColor = vbBlack

do

Timer 2. Enabled = true

Start Timer2 and display the screen saver scrolling text.

Multiple activities

Transfer control to detect mouse and keystroke behavior.

Loop until quitflag = True.

Run the screen saver to scroll the text until there is a mouse and key action.

Timer 2. Enabled = False

End scrolling text

Timer 1. Enabled = true

Start the timer 1 and exit the screen saver.

Other cases

Unload me.

outlet connection

End selection

End joint

Private Sub-Form _Unload (Cancel to Integer)

Dimension x

X = ShowCursor (true)

Display mouse

End joint

Private sub-timer 1_Timer ()

Unload me.

Exit the screen saver.

End joint

Private sub timer 2_Timer ()

Display horizontal scrolling text

lleft = lleft + 100

If lleft & gt =11810, then

lleft = 0

Lab 1。 Top = Int(Rnd * 7000)

If ... it will be over.

Lab 1。 Left = left

Timer 2. Enabled = False

End joint