Design Screen saver with VB6.0

Source: Internet
Author: User
Tags abs integer

The Windows operating platform has a screen saver, which is the screen saver feature. It is not uncommon for people who use computers on Windows operating platforms to have a few screen savers that the system provides to us, no novelty, or whether they want to design their own screen saver. The following describes how to use VB to design the user's own screen saver program. The screen saver protects the display from damage while conserving energy. As a screen saver, you should have the following characteristics:

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 the mouse or press the keyboard, screen protection ends, back to normal operation status. To implement these features, when writing a VB application, you can use the following methods:

1, change the form properties usually VB application forms have a border form appearance, but as a screen saver, you should set the form to have no border, and to maximize.

2. Hide and display the mouse cursor hides and displays the mouse cursor in a Visual Basic application the API function of Windows, which is named ShowCursor, needs to be used. Displays the mouse cursor when invoked with the parameter value True, and the mouse cursor is automatically hidden when invoked with the parameter value false.

3, the detection of mouse movement VB has a detection of Mouse Movement object event MouseMove event. MouseMove events are usually triggered when the application starts, and sometimes the MouseMove event can still be triggered when the mouse is not moved. Therefore, if the mouse has been moved directly in the program using the MouseMove event, it does not correctly reflect the movement of the mouse. You should write code in the MouseMove event to control it.

In order to correctly reflect the movement of the mouse, first use the variable record of the program running the current position of the mouse, and then use another set of variables to record the position of the mouse after moving, when the mouse before and after the position difference is greater than a certain range, triggering MouseMove event. Write the code 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
 ’把当前的鼠标值赋给orignX和orignY
 orignX=X
 orignY=Y
 ’初始化currentX和currentY
 if currentX=0 and currentY=0 Then
  currentX=orignX
  currentY=orignY
  Exit Sub
 Endif
 ’当鼠标移动大于一个象素时,显示鼠标光标并退出程序
 If Abs(oriqnX-currentX)>1 or Abs(orignY-currentY)>1Then
  X=ShowCursor(True)
  End
 Endif
EndSub

4, detect the mouse click in Visual Basic, click the event is triggered by "click". The program runs terminated when a click event is encountered while the screen saver is running. The code is edited as follows:

Private Sub Form-Click()
 X=ShowCursor(True)
 End
EndSub

Notice that the cursor is displayed as true before the end to avoid losing the cursor after the program is finished.

5, detect the status of keys on the keyboard the keyboard activity in Visual Basic is triggered by KeyDown. The code is the same as the code that clicked the event.

Private Sub Form-KeyDown(KeyCode As Integer,Shift As Integer)
 X=ShowCursor(True)
 End
EndSub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.