Use VB6.0 design screen saver

xiaoxiao2021-03-06  43

The Windows Operating Platform has a screen of protection, namely screen protection. People who often use the computer on the Windows operation platform are not very normal, and there is no freshness, no freshness, or I want to design the screen saver. Here's how to use VB to design users of your own screen saver. The screen saver can protect the display from being damaged while saving energy. As a screen saver, it should have the following characteristics:

Align = "marginwidth =" 0 "marginheight =" 0 "src =" http://images.chinabyte.com/adjs/iframe-pip/y-software-pip.html "frameborder =" 0 "width =" 360 "Scrolling =" no "height =" 300 "> src =" http://www.my5757.com/tj/adbottom.htm "frameborder =" 0 "width =" 365 "scrolling =" height = " 50 "> 1) When the screen saver is running, the mouse cursor is automatically hidden and the cursor is displayed at the end of the program. 2) When you click, move your mouse or press the keyboard, the screen protection ends, returns to normal operation. In order to achieve these features, the following methods can be employed when writing VB applications:

1. Changing the form properties typically VB application forms use a border form appearance, but as a screen saver, you should set the form as boundless box and maximize it.

2. Hide and show mouse cursors Hide in the Visual Basic application and display mouse cursors require the use of Windows API functions, which is called showcursor. The mouse cursor is displayed when called with the parameter value true, and when the parameter value FALSE is used, the mouse cursor is automatically hidden.

3. Test the mouse mobile VB has a target event mousemove event that detects the mouse movement. MouseMove events typically trigger at the time of startup, sometimes the mousemove event is likely to be triggered in the case where the mouse is not moved. Therefore, if the mouse is moved directly in the program, the mouse movement is not correctly reflected correctly. Code should be written in the MouseMove event.

In order to correctly reflect the mouse movement, first use variables to record the current position of the program run, then record the mouse moving position with another set of variables, trigger the mousemove event when the position difference before and after the mouse moves. The write code is as follows:

Private Sub Form-MouseMove (Button As Integer, shift As Inteqer, X As Single, Y As Single) Static currentX, currentY As Single Dim orignX, orignY As Single 'value assigned to the current mouse orignX and orignY orignX = X orignY = Y 'Initialization Currentx and Currenty IF Currentx = 0 and currenty = 0 THEN CURRENTX = Orignx currenty = Origny EXIT SUB Endif' When the mouse is greater than one pixel, the mouse cursor is displayed and exits the program if ABS (OriQnx-currentx)> 1 or ABS (Origny-Currenty)> 1Then X = showcursor (True) End endifendsub4, detecting a mouse click In Visual Basic, click the event to be triggered by "Click". When the screen saver is running, the program is terminated. The code editing is as follows:

Private suform-click () x = showcursor (true) endendsub

Note that the display of the cursor is true before the end, so as not to lose the cursor after the end of the program.

5. The keyboard activity in the state of each button on the keyboard is detected by Keydown triggered. The code is the same as the code that click the event.

Private Sub Form-KeyDown (Keycode As Integer) x = showcursor (true) endendsub

Below we will design a simple screen saver, when the program is run, from left to right, the image appears from the left side of the screen, and disappears on the right side of the screen, like the scaes, and keep the process. Assume that the picture file is named PIC.BMP and stored in the Windows folder. The actual operation is as follows:

Create a new project, add a picture box and a Timer control in the form. Set their properties as follows:

Form BackColor = & H80000007 & BorderStyle = 0 'NoneMaxButton = False MinButton = False Windowstate = 2' MaximizedTimer Intelval = 5PictureBox BackColor = & H80000007 & BorderStyle = 0 'None AutoSize = Ture

The input code is as follows:

'Declaration section of the form declares the showcursor function. Private Declare Function Showcursor LIB "User32" (BY VAL BSHOW AS Long) AS long 'When you click on the Mouse, you're on the form of private sub form-click () x = showcursor (true) ends endsub' When the button exits the program private subform-keydown (Keycode As INTEGER, SHIFT AS INTEGER) X = showcursor (TRUE) EndSub 'Load Form Hide Mouse Private Sub Form-Load () DIM X As long x = showcursor (false) Picture1.visible = false picture1.picture = loadPicture ("c: /windows/pic.bmp") Picture1.Left = -Picture1.Width EndSub 'Exits Private Sub Form-MouseMove (Button As Integer) on the Form , Shift As Integer, X As Single, Y As Single) Static currentX, currentY As Single Dim orignX, orignY As Single 'value assigned to the current mouse orignX and orignY orignX = X orignY = Y' and initialization CurrentX currentY If currentX = 0 And currentY = 0 Then currentX = orignX currentY = orignY ExitSub EndIf If Abs (orignX-currentX)> 1 Or Abs (orignY-currentY)> 1 Then X = ShowCursor (True) End EndIfEndSubPrivate Sub Picture1-Click () X = ShowCursor (TRUE) EndendsubPrivate Sub Picture1-KeyDown (Keycode As INTEGER, Shift as integer) x = showcur sor (True) EndEndSubPrivate Sub Picture1-MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single) Static Xlast, Ylast As Single Dim Xnow, Ynow As Single Xnow = X Ynow = Y If Xlast = 0 And Ylast = 0 Then Xlast = Xnow Ylast = Ynow ExitSub EndIf If Abs (Xnow-Xlast)> 1 Or Abs (Ynow-Ylast)> 1 Then X = ShowCursor (True) End EndIfEndSubPrivate Sub Timer1-Timer () Picture1.Visible = True Picture1 .Top = (form1.height-picture1.height) / 2 Picture1.left = Picture1.Left 50 if Picture1.Left> form1.Width Then Picture1.Left = -Picture1.width Endif overSub

转载请注明原文地址:https://www.9cbs.com/read-51671.html

New Post(0)