Click here to Skip to main content
Click here to Skip to main content

A Complete Screen Saver Framework Using MFC

By , 25 Oct 2002
 

Introduction

Here is a complete screen saver framework. It is based on the MFC sample "SAVER: Screen Saver" that comes with Visual C++. But I added more functionality so that it does everything a screen saver needs to do. To help you understand it and insert your own code, I removed all the drawing code so that it is as simple as possible (blank screen). In addition, I wrote a simple installation program. This installation program puts the screen saver (saver.scr) into its resource so that only one executable file (sinstall.exe) needs to be distributed. The Project Workspace contains two projects. One is the screen saver itself, another is the installation program.

In most cases, you will only need to make the following modifications.

  • Add drawing code in the drawwnd.h and drawwnd.cpp.
  • Add a configuration dialog box, launch it in the CSaverApp::DoConfig() function of the saver.cpp.
  • Add your own resource if any (resource.h and saver.rc).

For your reference, I list some Web sites related to Windows screen saver programming here.

Happy Screen Saving!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Chen Su
Software Developer
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalupdate for VS 2003memberJim Dill15 Jun '07 - 4:04 
Thanks for this handy framework!
 
I brought it into VS2003, converted projects as offered, and ran into two build problems: (1) had to change HTASK to DWORD in the arg list of OnActivateApp; (b) removed Enable3dControls calls in InitInstance -- doc says these are no longer needed.
 
-- Jim
GeneralProgram not compilingmemberAdeel68823 May '06 - 20:32 
I tried downloading your code and run it but it generates compile time error and says "Debugging Information Corrupt; recompile module.
 
Is this program helpful if i want to crate screensaver out of flash files (.swf)?
GeneralRe: Program not compilingmemberChen Su24 May '06 - 6:40 
Do a Rebuild.
 
Yes, this is simply a framework. You can do whatever you want on top of the framework.
GeneralNice little frameworkmemberreggie758 Feb '06 - 9:50 
Thanks, liked this sample.

 
Hi, I'm a .sig virus! Copy me to your .sig file and help me propagate!
GeneralNice FrameWork!memberThatsAlok6 Jul '05 - 2:30 
It's solved lot's and lot's of problem faced by me Smile | :) .
Thanks
 

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

cheers,
Alok Gupta

Generalscreen saver & Flash animationmember_roh_26 Sep '03 - 2:12 
Help me, please!
 
I have to write a screen saver that runs another application if found (a .EXE Flash animation running in a full screen window). This animation will work as the screen
saver window.
I have these problems:
1. How can I control mouse and keyboard events sent to animation window?
I think with same hooks but I don't know how to use them. Frown | :(
 
2. How can I control that the activated window is the one created by the animation
(i.e. if another application pops up its window screen saver must exit)? Cry | :((
 
3. There are other events I have to control? Confused | :confused:
 
Please, help me. This is my first Windows application and I don't know where I can find some info about this matter.
 
Thanks. Big Grin | :-D
 
PS: I beg your pardon for my dreadful English! Sigh | :sigh:

GeneralCenter of screen and screen depthmemberjoelparker17 Sep '03 - 13:32 
I am drawing pictures to the screen and wanted to know how I can find the center of the screen. Also do you know a way to determine the users screen resolution? (ie. pixel coords (1152 x 864 pixels)?
 
Joel Parker
GeneralRe: Center of screen and screen depthmemberChen Su17 Sep '03 - 17:07 
const int nWidth = ::GetSystemMetrics(SM_CXSCREEN);
const int nHeight = ::GetSystemMetrics(SM_CYSCREEN);
 
const int nCenterX = nWidth / 2;
const int nCenterY = nHeight / 2;
Generalinstallmemberglowas12 May '03 - 9:59 
How can I make your install program work with my saver.scr???Confused | :confused: Confused | :confused: Confused | :confused:
GeneralBrowsermemberglowas10 May '03 - 12:00 
I'd like instead of animation have a browser that displays my home page.
I was thinking to host an activeX control in a window. Which window should host it?
Or
maybe I should change CDrawWin with CHtmlView?
Just asking for the opinion.
GeneralRe: BrowsermemberChen Su10 May '03 - 18:32 
You can host the Web browser control in the CDrawWin window. Remember to call AfxEnableControlContainer() in the InitInstance().
GeneralRe: Browsermemberglowas12 May '03 - 4:34 
Thanks. I added the Web Browser control by creating it in OnCreate member function of CDrawWin.
However, now I see te mouse over the browser component and I can see the cursor.
Only keyboadr keys are closing the saver. It gets wors when I click into web browser component, then I cannot close the saver at all.
 
Where should I handle those messages and how?
Poke tongue | ;-P
GeneralRe: Browsermemberglowas12 May '03 - 5:39 
I called the CWnd::SetCapture() function in the CDrawWnd::OnCreate() to let CDrawWnd object capture all mouse messages.
AND that solve my problem.
 
Could I do it some other way?Big Grin | :-D
GeneralRe: BrowsermemberChen Su12 May '03 - 8:23 
That's the correct way to do it.
GeneralRe: Browsermemberglowas12 May '03 - 8:28 
thanks.
GeneralRe: Browsermemberglowas12 May '03 - 8:26 
You disable cursor icor within the framework. I load this webbrowser control that enables cursors back.
Is it posible to stop the webbrowser component from setting cursor back?
GeneralRe: BrowsermemberChen Su12 May '03 - 8:41 
Try calling ::SetCursor(NULL) or ::ShowCursor(FALSE) after the Web browser is fully loaded. For example, post a user-defined message in CDrawWin::OnCreate() and then handle the message.
GeneralRe: Browsermemberglowas12 May '03 - 9:56 
You mean something like this:
in CDrawWnd::OnCreate()
{
//create browser component here
....
SendMessage( WM_SETCURSOR, 0, 0 );
}
 
BOOL CDrawWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
::SetCursor(NULL);
return 0;
}

GeneralRe: BrowsermemberChen Su12 May '03 - 10:07 
No.
 
1. Use PostMessage() instead of SendMessage().
 
2. Use a user-defined message (e.g., (WM_USER + 1)) instead of WM_SETCURSOR.
GeneralRe: Browsermemberglowas13 May '03 - 4:06 
Thank you.
Placing a call
::ShowCursor(FALSE);
In the user-defined hanler did the whole work.
Big Grin | :-D
GeneralAbout DLLmemberscrraja21 Feb '03 - 1:00 
U used some DLL files. Can U say about that DLL files.
Bcoz' we r going to develop screensavers using VC++. If u give some tipst it'll be helpful to us
GeneralRe: About DLLmemberChen Su21 Feb '03 - 6:56 
Sorry, I don't understand your question.
QuestionChange file name from saver.scr to another?sussAnonymous27 Jan '03 - 5:44 
Dear Sir:
 
Your screen saver sample code is very easy to modify. It bring me much convenience and let me know more about this issue. But I have a question. When I copy saver.scr to system directory, it shows "Saver" in the combo box of screen saver selecting dialog. If I change file name to "saverxxx.scr", it can shows "saverxxx" correctly(xxx = anything). If I use other name like "aaa.scr" or "bbb.scr", it always shows "Screen Saver" in the combox! Would you please give me a hand?
I want to write a "manager" to generate different savers which will show different photos and all these savers use the same file saver.scr .(The manager will change file name and prepare different photos for every saver) Does it possiable?
 
Thank you very much!
 

Best Regards,
Terry Hsu
Hsin Chu, Taiwan
AnswerRe: Change file name from saver.scr to another?memberChen Su27 Jan '03 - 18:38 
On Windows NT/2000/XP, if the screen saver has a string resource with ID 1, then this string is used as the description line for the screen saver in the Control Panel. If it does not have this string, or if it is on Windows 9x/ME, then the long filename of the screen saver is used.
 
Therefore, you need to change the IDS_DESCRIPTION string in the Saver.rc and the filename of the executable.
Generaldisplaye control in screensavermemberquzi20 Nov '02 - 23:20 
Perhaps this a stupidness question, but I curiousity... Is possible to displaye control (for exmpl static control) in a screensaver?
 
Thanksing you muchly for helpness.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 26 Oct 2002
Article Copyright 2002 by Chen Su
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid