Click here to Skip to main content
13,456,687 members
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 15 Aug 2012

A Simple Screensaver in C through Win32: CodeRain

, 16 Aug 2012
Rate this:
Please Sign up or sign in to vote.
ScreensSaver through fullscreen mode using Win32 APIs in C.


It all started with a day I was really pissed off with the default Windows XP screensavers. Nothing was really great about those screensavers and then I started thinking to write one on my own in C using Win32 APIs when I get time (usually by sparing time). I am much fascinated about all the graphics and other stuff too. But I knew that I could not do that all at a time not even in short time. So I started learning Win32 programming through "Programming by Windows by Charles Petzold". As a beginner in Win32 programming it was very difficult for me to grasp even the basics of Window programming as it is not much simple when compared to other console programs. 

This is not an expert article about creating screen savers. But I could somehow achieve by making the executable as a screen saver through very simple steps. It did work in my machine.  

I have used Visual Studio 2010 to write and compile the .C/.H source codes. I really insist to have a look at Charles Petzold's book even before looking into the attached code as the Windows programming model is all together a different approach.

If a fresher who never had experience dealing with GUI through Win32 happens to look at the source thinks that I am an alien. But believe me it is quite different to that of a console program. But it is really good.

I had the same feeling too while learning the concepts.


The source code provided in this article is written in C on Windows. It is just fine if you know something about how to program on a compiler through C. 

I am targeting this article to Beginners who would really want to do something in full screen and then displaying a pattern of characters which would bring some level of interest of your friends.  

All you can do is try to create a project in visual c++ or Visual studio and start adding the below mentioned files to it. 

Create a Win32 application and then start adding the below mentioned files to Source files and Header files from the downloadable.

  1. MyMain.c
  2. MyWallProcs.c
  3. MyResources.h
  4. MyWallProcs.h

As it is a multi-threaded program, to compile the code please follow the below instructions. 

Using VC++ 6.0

Whenever you create a multithreaded Windows program, you need to change something in the Project Settings dialog box. Select the C/C++ tab, and select Code Generation in the Category combo box. In the Use Run-Time Library combo box, you should see Single-Threaded for the Release configuration and Debug Single-Threaded for the Debug configuration. Change these to Multithreaded and Debug Multithreaded, respectively. This will change a compiler flag to /MT, which the compiler needs to compile a multithreaded application. In particular, the compiler inserts the LIBCMT.LIB filename in the .OBJ file rather than LIBC.LIB. The linker uses this name to link with the run-time library functions. 

How to create a Screen Saver:

1. Once you have compiled the source code which would finally generate a .exe file, make sure to copy that to a temporary location and then rename it to .scr file extension. For example: a.exe to a.scr.

2. Now copy the a.scr to "C:\\WINDOWS\\SYSTEM32" folder

3. Right click on Desktop and you should find the 'a' screen saver in the drop down list of screen savers. 

Now do your stuff from here on.  

Note: You could do the same thing with the CodeRain.exe available in the downloadable version. 

The .scr file does work on my machine as a screen saver. 

Now...lets look into the concept that I actually wanted to implement on a full screen window as a screen saver. 

A code pattern and below is the sample of the rain I wanted to create through this thread and even I want the tail of the tree to blink as well. So I will show you how I achieved the way of blinking the way I wanted it to be. Consider each line below as a level and the length of the total levels as a tree, example as below:

level-1: 1 1 1 1 1 1                                                                 
level-2: 1 1 1 1 1 1                                                                 
level-3: 1 1 1 1 1 1                                                                 
level-4: 1 1 1 1 1 1                                                                 
level-5  1 1 1 1 1 1                                                                 
level-6  1 1 1 1 1 1                                                                 
level-7  0 1 0 c  ^

Now keeping the levels below 7 as constants and try changing the values of the level 7. We can achieve the blinking in some way and though blinking of a character has several other different meanings too. But I wanted the blinking of the level-7 in this way and thought it would be really interesting. I was following through out my thread this logic and simultaneously printing any number of trees across the wall and dynamically choosing the height of the tree. It is easy, isn't it?

I thought to learn Win32 programming in C, this could be a real good mini-project for me and then I started thinking of an interesting concept code rain.  Below is the name of the thread which does the actual implementation of the CodeRain in the project.

VOID RunCodeRain(PVOID pvoid)  

Points of Interest

I have learned a few things while working with this project like below.

  1. Handling Win32 windows using raw APIs.
  2. Displaying Text on Output window at various Vertical and Horizontal positions.
  3. Various fonts and sizes of text.
  4. Fullscreen windows. 

and a lot more... 

It may not be the perfect code for experienced professionals, but it is ok for me that I have done something different. I will think on re-writing the entire screen saver again and again with enhanced functionality. 

But for now it is fine. Please reply with your valuable comments. 


This is version 0.1 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Clifford Nelson16-Aug-12 10:27
memberClifford Nelson16-Aug-12 10:27 
AnswerThis is not an article. Should have been a tip Pin
Clifford Nelson16-Aug-12 10:26
memberClifford Nelson16-Aug-12 10:26 
GeneralRe: This is not an article. Should have been a tip Pin
kiranbhatter16-Aug-12 10:36
memberkiranbhatter16-Aug-12 10:36 
are you voting me 1 or to the admin ?
GeneralMy vote of 1 Pin
shaown04715-Aug-12 19:56
membershaown04715-Aug-12 19:56 
GeneralMy vote of 1 Pin
Member 182669215-Aug-12 8:45
memberMember 182669215-Aug-12 8:45 
GeneralRe: My vote of 1 Pin
kiranbhatter15-Aug-12 8:48
memberkiranbhatter15-Aug-12 8:48 
GeneralRe: My vote of 1 Pin
Member 182669224-Jan-13 22:19
memberMember 182669224-Jan-13 22:19 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180322.1 | Last Updated 16 Aug 2012
Article Copyright 2012 by Zerr0cool
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid