A website for better software and better life in Internet!

   Chinese URLs

   Greeting Creator

   Input Tips Everyday

   Source Code
Java Applet Games
Visit webpage in VC
M3U Music List Editor
Input Tips everyday
Combox in HTML
Self-made Screen Saver
Model of Neural Network
Display Chinese Characters
Mouse in Maze, a classic game in math
Serial Port Communication

Source Code -> Self-made Screen Saver

Self-made Screen Saver

What's Screen Saver? that's a software to display some motion pictures to protect the computer screen when your pc is idle long. You can let the screen put on whatever you want. ALthough most of time people do not enjoy staring at the screen pictures, many still put on their favorist on the screen. For me, I just put a black screen when i leave my pc. More important for me, it is that when i come back to return to my pc, i want to know when i left. How long have i had a break? That is to say, i hope my screen saver can record the time for me. If you have the same wish as me, ok, I make it realized by programming.
It's simple to use SCRNSAVE.LIB to make a Screen Saver. Make a mainframe, and ask SCRNSAVE.LIB to take care of the events; What you should do is to dicide what should be shown in the display.
I found SCRNSAVE.LIB in the directory of VC98\LIB.
Now, let's check the mechanism of Screen saver in Win32: If there's no mouse and keyboard events in a specific period, a WM_SYSCOMMAND message with wParam=SC_SCREENSAVE will be generated. If there's no any active application recieve this message, Screen saver will be activated. Some software, such as DVDPlayer, recieve this message to prevent Screen Saver, but that's not our topic.
Now, our screen saver is activated, what can we do? Add a timer, that's it.

1st, Run your Visual C, and select "New/Project/Win32 Application", select "A typical hellowrold application", use default parameter.
2nd, Copy this source code to cover the origin.
#include "stdafx.h"
#include < windows.h>
#include < scrnsave.h>
#include < time.h>
#include "resource.h"

BOOL WINAPI RegisterDialogClasses(HANDLE );
LRESULT    WINAPI ScreenSaverProc(HWND hWnd, 
                UINT message, WPARAM wParam, LPARAM lParam)
    HDC hDC;    RECT rc;
    static int xpos;    //
    static int ypos;    //
    static char SlideText[] = "I like my computer";
    static UINT Timer;    //timer
    static char tmpbuf[32];
    switch (message)
    case    WM_CREATE:    //initiale
        xpos = 0;
        Timer = SetTimer(hWnd, 1, 500, NULL);    //0.5 second
        _strtime( tmpbuf );
        tmpbuf[8] = '-';
    case    WM_ERASEBKGND:
        break;    //I don't care. DefScreenSaveProc will do it.
    case    WM_TIMER:        //Motion picture
        hDC = GetDC( hWnd );
        GetClientRect( hWnd, &rc );
        FillRect( hDC, &rc, (HBRUSH) GetStockObject(BLACK_BRUSH) );
        SetTextColor( hDC, RGB(255*rand(), 255*rand(), 255*rand()));
        SetBkColor( hDC, RGB( 0,0,0 ) );
        TextOut( hDC, xpos - strlen(SlideText)*8, ypos, 
            SlideText, strlen(SlideText) );    //Move text 1
        _strtime( tmpbuf+9 );
        TextOut( hDC, GetSystemMetrics(SM_CXSCREEN) - xpos, ypos, 
            tmpbuf, strlen(tmpbuf) );    //move text 2

        xpos = ( xpos + 10 ) % ( GetSystemMetrics(SM_CXSCREEN) 
		                        + strlen(SlideText)*8 );
        ypos = ( ypos + 10 ) % GetSystemMetrics(SM_CYSCREEN);
        ReleaseDC( hWnd, hDC );
    case WM_DESTROY:
        KillTimer( hWnd, Timer );
        PostQuitMessage( 0 );
        return 0;
    return DefScreenSaverProc( hWnd, message, wParam, lParam); //

BOOL    WINAPI    ScreenSaverConfigureDialog(HWND HwND, 
            UINT message, WPARAM wParam, LPARAM lParam)
{    //Configure Dialog. You can do it yourself.
    return FALSE;

BOOL    WINAPI    RegisterDialogClasses (HANDLE  hInstance)
{    //unnecessary.
    return TRUE;
3rd, Draw an Icon.
4th, In Menu "Project/Setting/Link", add SCRNSAVE.LIB, and compile.
5th, rename mysaver.exe as mysaver.scr, and copy it to Windows directory.
How do you think about it now? is it too easy?

   Contact Info
  User Support Sales Question Webmaster

Copyright 1998-2002 Fadshop.net, Inc. All rights reserved.