Tutorials to .com

Tutorials to .com » Software » Vb » VB5.0 create a screen saver mystery

VB5.0 create a screen saver mystery

Print View , by: iSee ,Total views: 51 ,Word Count: 2089 ,Date: Wed, 26 Aug 2009 Time: 10:09 PM


Shenzhen Sheng-Chang Chen

---- Visual Basic 5.0 with the idea of object-oriented programming and visualization programming approach can be developed all kinds of multimedia applications, software designers drew much favor. The use of Visual Basic 5.0 can be very easy to set up a screen saver.
---- Screen Saver is mainly used to protect the display screen, to avoid being a long time still image burns. In addition, it's fascinating creative animation makes the gap in the machine can also feel the computer has brought many fun. Many computer enthusiasts will have their own DIY screen saver desire, in particular wanted to be able to reflect a personality, rich amenities a screen saver. This article describes a way to use Visual Basic 5.0 programming language method of making a screen saver for a creative passion and interest of fans trying.

---- In the win95 desktop right click pop-up menu, select Properties, set the interface on the display appears, there is a label is to set the screen saver. In the page screen, select the win95 package with PC standard screen saver, you can understand that a standard screen saver has the following characteristics:

---- 1. Can be on the label of the small "monitor" in the pre-Hin

---- 2. Click on "Preview" button to run the screen saver directly, without waiting for the scheduled time

---- 3. Click "Settings" button on the screen saver and other settings to speed the pace

---- The following discusses how to use a specific Visual Basic 5.0 or above design features of the standard screen saver, which is in the design of the screen saver should pay attention to several issues:

---- 1, the screen saver prior knowledge

---- Screen saver is based on. SCR for the suffix of the file is actually a standard Windows executable files, when compiled EXE extension was revised to SCR, will no longer build with the extension EXE executable file. Many talk about the article only talk about screen saver screen saver in the image display techniques, procedures and systems for the interface with little or unwilling to talk about involved, the author obtained through reverse engineering methods and parameters of its use. Screen saver and system interface between the use of very simple screen saver through the pass command line parameters to achieve, and its format:

ScrSave.exe App.scr / X nnnn

---- X for the command-line arguments, nnnn is the value passed to the program.

---- Command-line arguments mainly in the following categories:

---- / S or / s: start mode, display or preview a screen saver

---- / P nnn or / p nnn: Pre-obvious patterns, nnn a decimal number is a significant pre-handle the small display window

---- / c or a / c: set the mode, bring up settings window to set

---- / A or / a: password mode, adjusting the export settings so that the window (This article is deferring the discussion of this parameter, interested friend can try their own)

---- Second, to prevent the screen saver to run two instances of

---- Visual Basic provides an App object, it has a PreInstance property, if the current Visual Basic application, an instance is already running when he leaves, the property is set to True, in order to avoid running a screen saver for many instance. For the screen saver in the Screen Saver Properties window, due to significant pre-procedure is called a program, but also need to find a way to prevent the same name procedure to run a screen saver while the two examples. Process can call the FindWindow API to determine whether the system has another application is running. It requires two string parameters, one that the application class name, and the other said that the window's title bar:

Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

---- The following code shows how a typical App.PreInstance and FindWindow in a screen saver in the implementation.

Private Sub CheckShouldRun ()

Note: If the screen saver is already running, exit
If Not App.PrevInstance Then Exit Sub

Note: to determine whether the system has the same name as the screen saver is running
If FindWindow (vbNullString, APP_NAME) Then End

Note: set the instance name
frmCover.Caption = APP_NAME
End Sub

---- 3, in the screen saver to hide the mouse

---- ShowCursor API function allows Visual Basic applications to hide or show the mouse, each time with the parameter values True or False calls ShowCursor can show or hide the mouse. The following is ShowCursor API function statement:

Declare Function ShowCursor Lib "user32"
(ByVal bShow As Long) As Long

---- 4, detection of mouse movement

---- Mouse movement in the screen saver mode, the need to exit the program, but in the pre-explicit mode, and do not affect the program, so set RunMode global variable to determine whether the mouse works on the program. MouseMove event is used to detect the mouse movement, when the application starts, or even moving the mouse not actually the case, MouseMove events will be triggered once. Therefore, MouseMove event is triggered only record the current position of the mouse, only when the mouse actually move away from its starting position a large displacement before the termination of the screen saver. Concrete realization of the code is as follows:

Private Sub Form_MouseMove (Button As Integer,
Shift As Integer, x As Single, y As Single)
Static x0 As Integer
Static y0 As Integer

Note: non-screen saver mode exit process
If RunMode <> rmScreenSaver Then Exit Sub

Note: a large mouse exit
If ((x0 = 0) And (y0 = 0)) Or _
((Abs (x0 - x) <5) And (Abs (y0 - y) <5)) _
Then
Note: a small mouse movement
x0 = x
y0 = y
Exit Sub
End If

Unload Me
End Sub

---- 5, set the parameters to read and save

---- In Visual Basic,, SaveSetting function is provided in the Windows registry to save or create the private parameters of the application functionality. The syntax is:

SaveSetting appname, section, key, setting

---- SaveSetting function, such as the setting value is stored in HKEY_CURRENT_USER \ Software \ vb and VBA Program Settings \ appname \ section \ key under.

---- GetSetting function provides the application reads the Windows registry of private parameters of the function. The syntax is:

GetSetting (appname, section, key [, default])

---- If the GetSetting arguments in any one did not exist, GetSetting returns the default value. If the default value is omitted, then the return to zero-length string ("")。

---- Application procedures are as follows:

Public Sub SaveConfig ()
Note: Save settings to the registry parameters
SaveSetting APP_NAME, _
"Settings", "NumBalls", Format $ (NumBalls)
End Sub

Public Sub LoadConfig ()
Note: to read from the registry parameter, if not set, the default value of 1
NumBalls = CInt (GetSetting (APP_NAME, _
"Settings", "NumBalls", "1"))
End Sub

---- 6, the small-screen window to achieve significant pre -

---- To screen saver significantly small window in the pre-show up, first of all to obtain the command line in the pre-Hin window handle, use GetClientRect to obtain its size, through GetWindowLong get the current state of the window, set into a child window with SetWindowLong after the state back into the Windows configuration, using SetParent to protect the screen window to link the pre-window, child window significantly, and finally SetWindowPos the program significantly in the pre-window is displayed. Procedures used in the GetClientRect, GetWindowLong, SetWindowLong, SetParent, SetWindowPos these API functions, these functions are given here, the statement:

Declare Function GetClientRect Lib "user32"
(ByVal hwnd As Long, lpRect As RECT) As Long

Declare Function GetWindowLong Lib "user32" Alias "
GetWindowLongA "(ByVal hwnd As Long,
ByVal nIndex As Long) As Long

Declare Function SetWindowLong Lib "user32"
Alias "SetWindowLongA" (ByVal hwnd As Long,
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function SetParent Lib "user32"
(ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long

Declare Function SetWindowPos Lib "user32"
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long,
ByVal x As Long, ByVal y As Long, ByVal cx As Long,
ByVal cy As Long, ByVal wFlags As Long) As Long


Case rmPreview Note: Pre-explicit mode Note: To get the window handle of the pre-Hin
preview_hwnd = GetHwndFromCommand (args)

Note: To get the pre-explicit window size
GetClientRect preview_hwnd, preview_rect

Load frmCover

Note: Set the "Preview" window name
frmCover.Caption = "Preview"

Note: To get the current window state
window_style = GetWindowLong
(frmCover.hwnd, GWL_STYLE)

Note: The current window is set to the child window state
window_style = (window_style Or WS_CHILD)

Note: Set the current window state
SetWindowLong frmCover.hwnd, _
GWL_STYLE, window_style

Note: Set the current window to the pre-window, child window significantly
SetParent frmCover.hwnd, preview_hwnd

Note: the pre-window handle significant windows into the structure of the current window
SetWindowLong frmCover.hwnd, _
GWL_HWNDPARENT, preview_hwnd

Note: Pre-explicit screen saver
SetWindowPos frmCover.hwnd, _
HWND_TOP, 0 &, 0 &, _
preview_rect.Right, _
preview_rect.Bottom, _
SWP_NOZORDER Or SWP_NOACTIVATE Or _
SWP_SHOWWINDOW

---- 7, it is important attribute

To modify the properties of the form has the following
BackColor = & H00000000 & background color to black
BorderStyle = 0 Notes: None Window border-free
ControlBox = 0 Note: False controls without
MaxButton = 0 Note: False maximize button-free
MinButton = 0 Note: False Minimize button without
ScaleMode = 3 Note: Pixel ratio model, Pixel
WindowState = 2 Note: Maximized window state is initialized as the maximum

---- Timer control (in the Form form) Enabled attribute in the design environment is set to False.

---- The following gives a complete screen saver example, its demonstration effect: a few small balls non-stop bouncing on the screen. Interested in friends can be program InitializeBalls and tmrMoveBalls_Timer two processes to modify , we can generate a variety of wonderful screen saver, such as adding text mobile display, star-picture show ...

---- When you complete these modifications to generate an SCR file, put it into the Windows 95 under the System directory, open the Screen Saver Properties window, choose your own screen saver, click the preview, enjoy yourself a masterpiece How does it feel?

---- The program in Visual Basic 5.0, Windows 95 environment to run through the


Visual Basic Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.