Link to home
Start Free TrialLog in
Avatar of dafoki
dafoki

asked on

Screen Saver

I need an example for a screen saver
with out MFC
Avatar of abancroft
abancroft

From MSDN:

Each screen saver must support a window procedure named ScreenSaverProc. Like most window procedures, ScreenSaverProc processes a set of specific messages and passes any unprocessed messages to a default procedure. However, instead of passing them to the DefWindowProc function, ScreenSaverProc passes unprocessed messages to the DefScreenSaverProc function. Another difference between ScreenSaverProc and a normal window procedure is that the handle passed to ScreenSaverProc identifies the entire desktop rather than a client window. The following example shows the ScreenSaverProc window procedure for the sample screen saver.

LONG WINAPI ScreenSaverProc(hwnd, message, wParam, lParam)
HWND  hwnd;
UINT  message;
DWORD wParam;
LONG  lParam;
{
static HDC          hdc;    /* device-context handle */
static RECT         rc;     /* RECT structure */
static UINT         uTimer; /* timer identifier */
 
    switch(message)
    {
        case WM_CREATE:
 
            /* Retrieve the application name from the .rc file. */
 
            LoadString(hMainInstance, idsAppName, szAppName, 40);
 
            /* Retrieve the .ini (or registry) file name. */
 
            LoadString(hMainInstance, idsIniFile, szIniFile,
                MAXFILELEN);
 
            /* Retrieve any redraw speed data from the registry. */
 
            lSpeed = GetPrivateProfileInt(szAppName, szRedrawSpeed,
                DEFVEL, szIniFile);
 
           /*
            * Set a timer for the screen saver window using the
            * redraw rate stored in Regedit.ini.
            */
 
            uTimer = SetTimer(hwnd, 1, lSpeed * 1000, NULL);
            break;
 
        case WM_ERASEBKGND:
 
           /*
            * The WM_ERASEBKGND message is issued before the
            * WM_TIMER message, allowing the screen saver to
            * paint the background as appropriate.
            */
 
            hdc = GetDC(hwnd);
            GetClientRect (hwnd, &rc);
            FillRect (hdc, &rc, GetStockObject(BLACK_BRUSH));
            ReleaseDC(hwnd,hdc);
            break;
 
        case WM_TIMER:
 
           /*
            * The WM_TIMER message is issued at (lSpeed * 1000)
            * intervals, where lSpeed == .001 seconds. This
            * code repaints the entire desktop with a white,
            * light gray, dark gray, or black brush each
            * time a WM_TIMER message is issued.
            */
 
            hdc = GetDC(hwnd);
            GetClientRect(hwnd, &rc);
            if (i++ <= 4)
                FillRect(hdc, &rc, GetStockObject(i));
            else
                (i = 0);
            ReleaseDC(hwnd,hdc);
            break;
 
        case WM_DESTROY:
 
           /*
            * When the WM_DESTROY message is issued, the screen saver
            * must destroy any of the timers that were set at WM_CREATE
            * time.
            */
 
            if (uTimer)
                KillTimer(hwnd, uTimer);
            break;
    }
 
   /*
    * DefScreenSaverProc processes any messages
    * ignored by ScreenSaverProc.
    */
 
    return DefScreenSaverProc(hwnd, message, wParam, lParam);
}
 
Do u want the program using Windows Fns or u want to make a screen saver using Windows hook.
look despite what the samples say, all a screen saver is is a program that takes command line input and parses it for the screen saver commands that windows sends. To find out what they are just take a look at the command line of your app when you rename it to a .scr file. Then parse for thoses inputs.
What!!!!

What inputs? Give some examples.
ok, I will give a example after school, I have to get back to work now. I will show you at 4:30
ok, windows passes "s" when it is starting the screen saver. "c" when it is asking for a configeration, and "p" when it is asking for a password.
After doing some digging I find that you are correct, ASSUMING that the screen saver library is NOT used.

If the screen saver library is used, it takes care of this detail.

However, it (the screen saver library) also takes care of a bunch of other messages. e.g. WM_SETCURSOR, WM_ACTIVATE, WM_ACTIVATEAPP etc.
Avatar of dafoki

ASKER

laeuchli
i tried whats you said and it's not working
well what part is not working? What did you want it to do that it's not doing? It does not setup your screen or look for mouse movements or anything.show me your code.
laeuchli did you meant that the screen saver argument should "s" for the screen saver to run and "c" for the configeration to come up?


ASKER CERTIFIED SOLUTION
Avatar of laeuchli
laeuchli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dafoki

ASKER

it works