Screen Savers

This is a discussion on Screen Savers within the Windows Programming forums, part of the Platform Specific Boards category; I was just wondering how screen savers should be properly created. I once created a program that I wanted to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    Question Screen Savers

    I was just wondering how screen savers should be properly created. I once created a program that I wanted to run as a screen saver, so I changed its extension and put it in the windows directory. It worked in the sense that I could get it running when the time elapsed, but if I ever loaded the screen saver chooser and chose my program, it would automatically run.

    Thanks for the help.
    genghis

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    The windows sdk offers the scrnsave.lib for you create a simple screensaver with 3 functions

    1 to run as the windows procedure;

    Code:
    LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam,LPARAM lParam){}
    1 to initialise a configuration dilog box (Optional, but must be created- if you dont want to use it, return 0);

    Code:
    BOOL WINAPI ScreenSaverConfigureDialog(HWND hdWnd,UINT dMessage, WPARAM wParam, LPARAM lParam){}
    and 1 to register a custom windows class(Again optional - if you dont want to use it return 1);

    Code:
    BOOL WINAPI RegisterDialogClasses(HANDLE hInstance){}
    You also need as a minimum, the following resources;

    an icon called ID_APP and a string table with a single entry called IDS_DESCRIPTION (Just enter a title for the actual text)

    Then in the ScreenSaverProc, you will recieve 1 WM_CREATE, 1 WM_ERASEBKGND to begin (use the later to clear the screen). At the end you will get a WM_DESTROY. Now in the WM_CREATE, make a timer to feed a WM_TIMER, and when you get that message, treat it as you would a WM_PAINT in a normal app.

    Sorry if I am a little vague, but I will try post an example later when I get home from work

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    thx

    Yeah, thanks a lot. I kind of get the picture but I don't understand how it all works out exactly.

    For instance, I understand the Dialog Box and string but I don't understand why there is a need for a special ScreenSaverProc. Can't I just create a window like I normally do (only popup on the whole screen) and then handle it through normal processing?

    Still, thx.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Yeah, you can create your own window....

    The ScreenSaverProc is just a bog standard windows precedure, but it hadns all default messages it doesnt process to another function called DefScreenSaverProc() which is part of the scrnsave library and ensures that the prog closes on WM_KEYDOWN, WM_KEYUP, WM_MOUSEMOVE and some other windows messages (See MSDN)

    The library is just saving you hassle

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    To add a tiny bit to the fine suggestions already:

    To create a screen saver without using scrnsave.lib you would have to compile your program as normal and then change its extension to 'scr'. Nothing different there.

    In your program you have to get a hold of the command line which contains information about what is expected of your screen saver. If you get a 'c' then that means it's time to display the 'configuartion dialog' which is the thing you see with the little monitor in the screen saver properties window. With the c comes an int value which you cast to a wnd handle - it's the handle of the screen saver properties dialog (it might be a dc, not sure?) so that you can draw a wee version of your screen saver in the 'monitor' of the screensaver property page, if you want.

    If you get 'p' then it's screen saver mode and so you launch the full bifter in all it's colourful glory. I'm not sure about the exact nature of these flags because it's a while since i've done this but they should be easy enough to check (use a MessageBox, for example).

    You also have to trap the SC_SCREENSAVE flag of the WM_SYSCOMMAND to make sure that only one instance of the screensaver is running. Make sure you send all other flags to the system for default processing.

    The other thing you have to do is monitor keyboard and mouse messages for cancellation of the screen saver. Pay particular attention in your WM_MOUSEMOVE handler because for some strange reason, windows will send a heap of these messages to your scr app when it starts - causing it to cancel right away! I just ignored the first 4 msgs which seemed to work ok.

    And after all that rambling I finally found a link to an excellent discussion and explanation:

    http://www.wischik.com/scr/howtoscr.html

    enjoy!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM
  5. Screen Savers
    By Nor in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2002, 05:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21