C# Screen Saver Programming Assignment: Creating a Windows Screen Saver - Prof. Frank Mcco, Assignments of Computer Science

Instructions for creating a windows screen saver using c#. It covers the different modes of operation, including configuration mode, preview mode, and full-screen mode. The document also explains how to store and retrieve settings from the windows registry and how to use the iswindowvisible and getclientrect win32 api functions in preview mode. A simple screen saver example is provided for demonstration.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-cbj
koofers-user-cbj 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Extra Credit Assignment – C# Screen Saver
GUI Programming
%1 added to final grade
A Windows screen saver is simply a Windows application that displays either an options dialog box, a preview
screen, or a full-screen window, depending on the command line argument it receives. Windows screen savers
have a .scr extension and are typically stored in the Windows system directory.
Argument Action
/c Configuration mode
/p Preview mode
/s Full-screen mode
Your program can determine which mode your program is to execute by examining the command line
parameters in Main:
static void Main()
{
string[] cmdList = Environment.CommandLine.Split(' ');
// First command-line param is the exe name, second param is the mode
if (cmdList.Length >= 2) {
if (cmdList[1].IndexOf("/c") >= 0) { // Configuration mode
Application.Run(new OptionsForm());
return;
}
parentHwnd = IntPtr.Zero;
if (cmdList[1] == "/p") { // Preview mode
previewMode = true;
// Handle to preview dialog box is next command-line param
parentHwnd = (IntPtr) uint.Parse(cmdList[2]);
}
}
Application.Run(new ScreenSaverForm());
}
The parentHwnd will be used in preview mode and is discussed in the preview mode section. The
ScreenSaverForm is a Windows Form that will need to fill the entire screen. This is done by setting the
ScreenSaverForm’s WindowState property to Maximized and FormBorderStyle to None. The OptionsForm is
just a Windows Form that looks like a typical dialog box for setting properties of the screen saver.
Configuration Mode
In configuration mode, the screen saver should launch a dialog
box that allows the user to control the appearance and settings of
the screen saver. Typically these settings are stored in the
Windows Registry. The Registry is a hierarchical repository of
information used by Windows and applications for storing various
types of configuration data.
The following code segment shows how information can be
stored in and retrieved from the Registry:
pf3

Partial preview of the text

Download C# Screen Saver Programming Assignment: Creating a Windows Screen Saver - Prof. Frank Mcco and more Assignments Computer Science in PDF only on Docsity!

Extra Credit Assignment – C# Screen Saver

GUI Programming

%1 added to final grade

A Windows screen saver is simply a Windows application that displays either an options dialog box, a preview

screen, or a full-screen window, depending on the command line argument it receives. Windows screen savers

have a .scr extension and are typically stored in the Windows system directory.

Argument Action

/c Configuration mode

/p Preview mode

/s Full-screen mode

Your program can determine which mode your program is to execute by examining the command line

parameters in Main:

static void Main() { string[] cmdList = Environment.CommandLine.Split(' ');

// First command-line param is the exe name, second param is the mode

if (cmdList.Length >= 2) { if (cmdList[1].IndexOf("/c") >= 0) { // Configuration mode Application.Run(new OptionsForm()); return; }

parentHwnd = IntPtr.Zero;

if (cmdList[1] == "/p") { // Preview mode previewMode = true;

// Handle to preview dialog box is next command-line param parentHwnd = (IntPtr) uint.Parse(cmdList[2]); } }

Application.Run(new ScreenSaverForm()); }

The parentHwnd will be used in preview mode and is discussed in the preview mode section. The

ScreenSaverForm is a Windows Form that will need to fill the entire screen. This is done by setting the

ScreenSaverForm’s WindowState property to Maximized and FormBorderStyle to None. The OptionsForm is

just a Windows Form that looks like a typical dialog box for setting properties of the screen saver.

Configuration Mode

In configuration mode, the screen saver should launch a dialog

box that allows the user to control the appearance and settings of

the screen saver. Typically these settings are stored in the

Windows Registry. The Registry is a hierarchical repository of

information used by Windows and applications for storing various

types of configuration data.

The following code segment shows how information can be

stored in and retrieved from the Registry:

using Microsoft.Win32;

// Store in Registry RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\Demo_ScreenSaver"); if (key != null) Registry.LocalMachine.DeleteSubKeyTree("SOFTWARE\Demo_ScreenSaver"); key = Registry.LocalMachine.CreateSubKey("SOFTWARE\Demo_ScreenSaver"); key.SetValue("text", "some text");

// Read from Registry RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\Demo_ScreenSaver"); if (key != null) string text = (string)key.GetValue("text");

You can see the entries made in the Registry by using regedit. Run regedit by clicking on the Start button in the

task bar, selecting Run… and entering “regedit”. By very careful when using regedit… deleting or altering

any information may cause Windows or other applications not to function properly anymore.

Look under “My Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Demo_ScreenSaver” to see your setting.

Close regedit when you no longer need it.

Preview Mode

When the screen saver starts up in preview mode, it should run in a child window whose parent window is the

Display Property window as shown in the figure below. The handle to the Display Properties window is obtained

from the second command line parameter when the screen saver is executed in preview mode.