( Index )

Brief Information about the Nov '06 CSIG Meeting

Screen Saver - Colored Night Stars

C++ Version 7 and Visual Studio 2005

Written by B. Arnold

Colored Night Stars

Welcome to the CSIG, a Special Interest Group of the ACGNJ. The subject for this month is a simple screen saver program. It uses the latest C++ compiler in Microsoft's Visual Studio 2005. There are a number of ways to refer to this compiler and code. Here's what Wikipedia says:

The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 2.0
C++ 7.0
.Net 2.0
Common Language Infrastructure

And there are many new things to learn. This screen saver has been made much simpler by the advanced graphics of the new compiler. The program may also be compiled using the free C++ Express compiler.

Here are the details of this screen saver. The object of the program is to display random colored stars on a black background. (Note: this code does not handle multiple screens.) Algorithm: Create a regular CLI Windows Forms program. Redraw random stars every 4 ... 15 seconds. Remove border and hide cursor. Handle command line arguments of /c /p /s. Handle keyboard hit to close.

The program demonstrates the screen saver logic and graphical routines for the screen.

This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs and the "Express" versions are free ! Additionally, Borland has just announced that it also has four new programs that are also available in free versions. These are Turbo C++, Turbo C-Sharp, Turbo Delphi and Turbo Delpi for .NET. You may also want to check with Intel and others for their generally free evaluation versions.

The beginning of the evening (starting at 7:30pm) will be a RANDOM ACCESS discussion. The main presentation will discuss the program.

Our download site has code and programs from most of our meetings. ( Source Code Files )

Sample Code - VC7

Sample Code
#define MAXSTAR_X 175       // 70*10/4 = 175
#define MAXSTAR_Y 250       // 100*10/4 = 250

    private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {

                 Rectangle windowRect = ClientRectangle;
                 Graphics ^g = e->Graphics;

                 int scale, xorg, yorg;
                 for (int i=0; i<25; i++)
                     scale = pRand->Next(10) + 4;
                     if (windowRect.Right > MAXSTAR_X && windowRect.Bottom > MAXSTAR_Y)
                         xorg = pRand->Next(windowRect.Right-MAXSTAR_X);
                         yorg = pRand->Next(windowRect.Bottom-MAXSTAR_Y);
                     else xorg = yorg = 0;

                     // Create solid brush.
                     // SolidBrush^ redBrush = gcnew SolidBrush( Color::Red );
                     SolidBrush^ starBrush = gcnew SolidBrush(
                         255 >> pRand->Next(4),         // shift 0...3 places
                         255 >> pRand->Next(4),         // 255, 127, 63, 31
                         255 >> pRand->Next(4) ));

                     // Create points that define polygon.
                     Point point1 = Point(10,50);
                     Point point2 = Point(36,46);
                     Point point3 = Point(40,0);
                     Point point4 = Point(44,46);
                     Point point5 = Point(70,50);
                     Point point6 = Point(44,54);
                     Point point7 = Point(40,100);
                     Point point8 = Point(36,54);
                     array ^curvePoints = {point1,point2,point3,point4,point5,point6,point7,point8};

                     for (int i=0; iLength; i++)
                         curvePoints[i].X = (10 * curvePoints[i].X) / scale + xorg ;
                         curvePoints[i].Y = (10 * curvePoints[i].Y) / scale + yorg ;

                     // Draw polygon to screen.
                     g->FillPolygon( starBrush, curvePoints );

"Random Access" questions start at 7:30 Tuesday night.


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page