Writing a screen saver with a compilation

Source: Internet
Author: User
Tags execution ini resource

What is the screen saver, I believe everyone has used, but for its structure may not be so familiar with. The screen saver is a special Envoy's. exe file, which is actually a standard PE file, except for the extension. SCR, which is also renamed with the. exe file that the connector produces. But in programming, Screen saver has its special place, in the mean is its programming specification.

The screen saver has the following features:

The screen saver is the Win32 API that supports a particular application and is automatically activated by the system. The mechanism is that when conditions are met, the system emits a word parameter WParam value of Sc_screensave for the current active window, and then executes system by the currently active window. INI file, the screen saver specified in the [boot] area.

The screen saver activation condition is that there is no mouse or keyboard input within the specified time, and that the current active window is a standard WINDOWS application. Wm_syscommand messages are ignored because of non-WINDOWS applications. Obviously, the screen saver can be disabled if the currently active program takes over the Wm_syscommand message with the character parameter WParam value Sc_screensave and does not pass to the DefWindowProc function. This is especially useful for some programs that are not willing to be interrupted, such as video playback, or disc burning programs.

You can select the screen saver you want in the Control Panel's display and configure the screen saver parameters. The configured dialog box is provided by the screen saver.

Here is the key to writing a screen saver:

The screen saver is written by the static link library scrnsave. LIB support, which contains the main program and default features to establish a screen saver, such as setting up a default Size full screen window for users to use, and providing the default message handler, which defaults to the following message:

Wm_setcursor--Sets the cursor to none

WM_PAINT--Painting screen background

Wm_lbuttondown, Wm_mbuttondown, Wm_rbuttondown, WM_KEYDOWN, wm_mousemove--Abort execution

Wm_activate--If WParam is FALSE, abort execution

The entry code for the program has been included in the Scrnsave.lib, the name is WinMain, so the end of the program is included in the WinMain.

The user only needs to write three basic functions that must be named Screensaverconfiguredialog, Screensaverproc, and registerdialogclasses, and these 3 functions must be in the. DEF file, specify export

Screensaverproc-The main process, that is, the window process of the main window that is automatically created, all processing of the screen is done by it. The unhandled message can be passed to the Defscreensaverproc function, and the system handles the default processing mentioned above. The default Defscreensaverproc process handles Wm_lbuttondown, Wm_mbuttondown; Wm_rbuttondown, WM_KEYDOWN, wm_mousemove messages and end the program, if you do not want to exit these messages, you can handle them, do not pass to Defscreensaverproc.

Screensaverconfiguredialog-handles the screen saver configuration dialog, which is not invoked by the main program, but by the monitor Setup program in the Control Panel. The configuration data entered by the user should be output to. INI or the registry.

Registerdialogclasses-Registers the window class of the Screen Saver Configuration dialog box, which can simply return TRUE if the standard dialog box is used.

In the Screensaverproc window process, there is a private message WM_ERASEBKGND--You can erase the background at this point, and if you pass this message to Defscreensaverproc, you get a completely black background.

You must rename the compiled. exe file to the. scr file when you use it, and then copy it to the Windows or Windows\System directory.

To make the control Panel recognizable, the screen saver icon must be defined as 100 in the resource file, and a description string must be included in the resource file. This string is used by the control Panel to display the screen saver's name. It must be at the top of the string table with an ID of 100. The ID of the Screen Saver Configuration dialog box in the resource file must be 2003.

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.